1 | initial version |
If I remember correctly Mat was introduced in OpenCV 2.0. The conversion can be done in the most straightforward way. What is sounds surprising to me is the error about 'synchronous data' that seems completely irrelevant. Can you please explain how you perform the conversion, and for what purpose?
2 | No.2 Revision |
If I remember correctly Mat was introduced in OpenCV 2.0. The conversion can be done in the most straightforward way. What is sounds surprising to me is the error about 'synchronous data' that seems completely irrelevant. Can you please explain how you perform the conversion, and for what purpose?
Edit:
I run your code and stored resulting image on the disk. Created image was OK. How do you look into the data? Maybe you are accessing it in some wrong way.
Next points are not related to question but are worth noting. There pretty much mess in the code. Lets try to sort out the problems. First lets deal with your first approach:
1) You are initializing Mat from constructor that returns IplImage. This will compile and run, but it will leak memory. cvCreateImage() is creating IplImage object, but there no IplImage object that may relesae it later. Your 'original' image is Mat object that is just another header that points to the same memory, and so it won't release it either.
2) Are you sure that w=col_size and h=row_size?
3) It is sort of pointless to cast 20 to char. Unlike IplImage the 'data' in Mat is array of unsigned char not array of char. Besides this cast will happen anyway even if you won't write it.
4) There no point in double for loop in order to set all values. Use setTo() if you work with Mat or cvSet() if you work with IplImage. Or just provide the value to constructor.
Now about second approach:
1) First you create IplImage object. So far its memory buffer is allocated but not initialized (i.e. can contain anything). Then you are creating Mat object with same parameters as IplImage, and forcing it to copy this memory buffer. What for? It is exactly the same as creating completely unrelated Mat.
2) Then you are taking image from ImageQueue without releasing previous one. This is again memory leak. B.t.w., what is this ImageQueue?
3) Then you are setting your 'original' image to point to the same place as current opcvImg. What was the point of initializing it before? After your OR statement you actually made copy of data, not just another pointer to existing data but the question remains.
Are you completelly sure you need IplImage at all? There almost nothing you can do with IplImage that you can't do with Mat.