pixel values different when read from C#

asked 2014-12-01 18:16:23 -0500

houmanr gravatar image

hi there, I am having some strange problems with opencv. I have a program written in C# which I converted to C and then I linked it with opencv. The C# version uses the native C# image loading libraries to read images and my C version uses imread from opencv 3 beta. However the output of the two programs are slightly different. After days of debugging I found out the source of the problem is the fact that the pixel values are different as read by imread in OPENCV and as read by C#. I printed a sample of these pixel values: (the pixels are RGBA and each row represents a single byte, so four rows would be one pixel):


byte    C#  opencv  diff
0   116 116 0
1   120 120 0
2   114 114 0
3   255 255 0
4   114 114 0
5   118 118 0
6   112 112 0
7   255 255 0
8   115 116 -1
9   119 120 -1
10  113 114 -1
11  255 255 0
12  119 120 -1
13  123 124 -1
14  117 118 -1
15  255 255 0
16  121 122 -1
17  125 126 -1
18  119 120 -1
19  255 255 0
20  119 119 0
21  123 123 0
22  117 117 0
23  255 255 0
24  119 120 -1
25  123 124 -1
26  117 118 -1
27  255 255 0
28  122 123 -1
29  126 127 -1
30  120 121 -1
31  255 255 0
32  125 125 0
33  129 129 0
34  123 123 0
35  255 255 0
36  120 119 1
37  124 123 1
38  118 117 1
39  255 255 0
40  119 120 -1
41  123 124 -1
42  117 118 -1
43  255 255 0
44  122 122 0
45  126 126 0
46  120 120 0
47  255 255 0

Please let me know if you have any idea why this is happening.

Thank you for your time, J

edit retag flag offensive close merge delete

Comments

Is it a jpg? Maybe it is the algorithm of coding/decoding. One may be older? Or it could be the problem of RGB->BGR? Normallly, OpenCV loads it in BGR, and if you interpret the B as R then there may be the problem...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-12-02 06:37:41 -0500 )edit

hi, and thank you for your reply. Those two are both great hints and I actually started from there. That is why i tested it on non-compressed images as well, such as bmp and the same results occurred. As for RGB vs BGR, i made sure i did not make any errors either. If you look at my table you see the corresponding values are nearly identical, so the channels have been correctly preserved. Thanks J

houmanr gravatar imagehoumanr ( 2014-12-02 13:43:51 -0500 )edit