使用EmguCV进行颜色分割

时间:2017-11-24 10:35:50

标签: c# unity3d emgucv threshold

上下文: 目标是创建一个跟踪convexHullDefects的脚本,以计算当前被跟踪的手指数量,并将此数字返回给Unity。

问题:我正在尝试对HSV图像执行阈值,因为HSV被认为是阈值的最佳颜色空间。然而,使用当前的代码,我似乎跟踪的不仅仅是绿色,这是我戴绿色手套的人的目标分割。我的棕色胡须被追踪为例。什么似乎是问题?

更多信息: 从网站" colorizer.org"

获得的色调,饱和度和价值

Example of current result

代码:

using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.Features2D;
using Emgu.CV.Util;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using Emgu.CV.Aruco;

public class GestureTrackingScript : MonoBehaviour
{

    public VideoCapture cap;
    public RawImage camImage;
    int iteration = 0;
    double hueMin = 102.0;
    double hueMax = 126.0;
    double saturationMin = 76.0;
    double saturationMax = 100.0;
    double valueMin = 25.0;
    double valueMax = 100.0;


    // Use this for initialization
    void Start()
    {
        Debug.Log("Startup initiated...");
        cap = new VideoCapture(0); // instantiate a webcamera
        cap.SetCaptureProperty(CapProp.Fps, 30); // The FPS of the camera

        Debug.Log("Startup finished. Running...");
    }

    // Update is called once per frame
    void Update()
    {
        Image<Hsv, byte> imgInput = cap.QueryFrame().ToImage<Hsv, byte>(); // the input image (frame from camera)


        imgInput = imgInput.ThresholdToZero(new Hsv(hueMin, saturationMin, valueMin));
        imgInput = imgInput.ThresholdToZeroInv(new Hsv(hueMax, saturationMax, valueMax));


        MemoryStream _memory = new MemoryStream();
        imgInput.Bitmap.Save(_memory, imgInput.Bitmap.RawFormat);
        Texture2D camera = new Texture2D(400, 400);
        camera.LoadImage(_memory.ToArray());
        camImage.texture = camera;
        camImage.material.mainTexture = camera;
        Debug.Log("Ping Number " + iteration);
        iteration++;

    }
}

0 个答案:

没有答案