Reading jpg file in OpenCV vs C # Bitmap

After many experiments, I found that reading a jpg file in C ++ format (OpenCV):

auto temp(cv::imread("xxx.jpg");

different than reading the same file using C # bitmap:

var temp=new bitmap("xxx.jpg");

The results are different. There is a noticeable difference if I apply some kind of algorithm to them like GoodFeatureToTrack.

Question: How can I adapt the method of loading raster C # in OpenCV. So, I got the same result if I upload my image directly in the native part or from C # Wrapper.

thanks

EDIT:

This code is C ++ - a function that takes some structure containing an image that has been loaded into a managed program (C #), and then loads the same image into opencv and compares them. There is another!

  extern "C" _declspec (dllexport) void test_diff(authenticator_reference_structure* referecnces){ auto image(cv::imread("white.jpg")); cv::imshow("opencv", image); auto wrpped(referecnces->references->images->image.getMat()); cv::imshow("C#", wrapped); cv::Mat ss; cv::absdiff(image, wrapped, ss); cv::threshold(ss, ss, 1, 255, CV_THRESH_BINARY); cv::imshow("Diff", ss); cv::waitKey(); } 

threshold difference image

+3
source share
2 answers

Perhaps you can use getImage() instead of getMat() ?

A similar question is being addressed here (using openCV in C #, not C ++)
http://www.emgu.com/forum/viewtopic.php?t=188

+3
source

As others pointed out, if you want to read an image in OpenMV unmodified, set the flags to -1 in the C ++ function , since in:

 cv::Mat img = cv::imread("xxx.jpg", -1); 

or use the specific enum value:

 cv::Mat img = cv::imread("xxx.jpg", cv::IMREAD_UNCHANGED); 

Also note that JPEG images are not guaranteed to be decoded bits, the same for different decoders! It is preferable to use a lossless format, such as PNG (see # 4148 , # 4046 , ...).

+2
source

Source: https://habr.com/ru/post/1233762/


All Articles