Question

I'm trying to convert a small opencv python script to emgu with C#.

In python the code

COLOR_MIN = np.array([104, 34, 255], np.uint8)
COLOR_MAX = np.array([124, 34, 255], np.uint8)
frame_threshed = cv2.inRange(hsv_img, COLOR_MIN, COLOR_MAX)
cv2.imshow("frame thresh", frame_threshed)

correctly thresholds the image which is displayed by cv2.imshow.

I've converted the code to C# as follows:

var min = new Hsv(104, 34, 255);
var max = new Hsv(124, 34, 255);
var thresh = hsvImg.InRange(min, max);
CvInvoke.cvShowImage("thresh", thresh);

Here only a black image is drawn - so nothing seems to be matching the threshold.

In both cases I'm using the same .PNG file as input. I wrote the python code on osx and the .net code is running inside a win8 VM - could this be something to do with color profiles?

Any tips or things to try to get the .NET version working would be greatly appreciated!! Thanks!

Was it helpful?

Solution

The issue seems to be I'm using an older version of emgu, and was going by the 2.4 docs for emgu in which the above should work.

In the version I'm using (2.2), the following works:

var min = new Hsv(103, 33, 254);
var max = new Hsv(125, 35, 256);
var thresh = hsvImg.InRange(min, max);
CvInvoke.cvShowImage("thresh", thresh);

instead of checking by <= and >= it's using < and >.

It's my fault for accidentally clicking the wrong package in NuGet... more reason to always use the command line ;).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top