Click here to Skip to main content
15,889,595 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to know how this function work, learning opencv computer vision book tell me cvNot() inverts every bit in every element of source but when i write this code
C#
float A[]={1,2,3,4};
 CvMat *Mat1=cvCreateMat(2,2,CV_8UC1);
 Mat1->data.fl = A;

cvNot(Mat1,Mat1);

Give me this result :
-4 2
3 4
what is wrong here!!!, this result is invert to each element in matricx {1,2;3,4} ????
Posted
Comments
Philippe Mori 26-Sep-13 21:17pm    
I don't know about cvNot but it seems that your original data is float then I think that CV_8UC1 would mean an 8 bit unsigned char.

By invert every bit, are you talking about the bit pattern. If so, I doubt you want to works on floating points.
[no name] 26-Sep-13 21:22pm    
Well OP code is wrong to begin with as you point out. It does work on floating point if that's what is required but inverting every bit on an fp number may produce an unexpected result which depends on particular implementation of fp.
[no name] 26-Sep-13 21:23pm    
Do you wish to invert uchar or floating point matrix elements?
Anderso0on 27-Sep-13 1:08am    
yes , and i hope you explain how this function inverse float or other datatype

1 solution

C++
float A[]={1,2,3,4};
CvMat *Mat1=cvCreateMat(2,2,CV_32FC1);
Mat1->data.fl = A;

cvNot(Mat1 , Mat1);

for(int i = 0; i < 2; i++)
    for(int j = 0; j < 2; j++)
        cout << CV_MAT_ELEM(*Mat1, float, i, j) << endl;

unsigned char B[]={1,2,3,4};
CvMat *Mat2=cvCreateMat(2,2,CV_8UC1);
Mat2->data.ptr = B;

cvNot(Mat2 , Mat2);

for(int i = 0; i < 2; i++)
    for(int j = 0; j < 2; j++)
        cout << CV_MAT_ELEM(*Mat2, unsigned char, i, j) << endl;


Here are 2 examples. The unsigned char should be easy to understand. You can use this to help.

C++
cout << (int) CV_MAT_ELEM(*Mat2, unsigned char, i, j) << endl;


For the float this may help (if you can see why the results all negative you probably understand it).

http://en.wikipedia.org/wiki/Floating_point[^]

See also
http://electronics.stackexchange.com/questions/9941/the-bitwise-complement-of-a-floating-point-numbers-binary-representation[^]
 
Share this answer
 
v3
Comments
Anderso0on 27-Sep-13 8:35am    
thanks ^_^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900