开发者

How to merge detected edges to a colour capture in Emgu CV

开发者 https://www.devze.com 2022-12-22 16:45 出处:网络
I am trying to make a C# desktop application (with Emgu CV wrapper) which captures the feed from the camera, detects edges in the feed and then displays the original feed (coloured) with the edges - s

I am trying to make a C# desktop application (with Emgu CV wrapper) which captures the feed from the camera, detects edges in the feed and then displays the original feed (coloured) with the edges - so somewhat of a comb开发者_如何转开发ined coloured feed and edges. I successfully get the feed from the camera. I also detect the edges in the feed by using the Canny method. The problem is that while the original feed is in colour, the detection of edges is done in grayscale (black background, white edges). I would like to know how to "merge" the colour feed with the edge feed to output a merged feed.

I've tried with the Copy method in Emgu CV but it outputs a black background and correctly coloured edges (so for instance if I hold a red cube in front of the camera, the edges around the cube are coloured red).

Any help is very appreciated.


OK, after a little bit of tinkering around I found the solution. The trick is to use the And function on an inverted Canny result and the colour feed. Here's my function that works with Application.Idle:

    private void processFunction(object sender, EventArgs e) {
        Image<Bgr, Byte> frame = c0.QueryFrame();
        Image<Gray, Byte> grayscale = frame.Convert<Gray, Byte>();
        grayscale = grayscale.Canny(new Gray(0), new Gray(255)).Not(); //invert with Not()
        frame = frame.And(grayscale.Convert<Bgr, Byte>(), grayscale); //And function in action
        imageBox1.Image = frame;

    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号