MiaoRong / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

cvSetImageROI + cvCopy produce ROI with incorrect Colour mode #221

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

IplImage frame, image;
CvRect face = CvRect(...);

cvSetImageROI(frame, face);
image = cvCreateImage(cvGetSize(frame), frame.depth(), frame.nChannels());
cvCopy(frame, image);
cvResetImageROI(frame); 

What is the expected output? What do you see instead?

It is expected that image now contains basically a cropped image, with same 
colour mode, etc.

What is produced is the correctly sized image, but with a different colour mode.

What version of the product are you using? On what operating system?

java-0.1-bin.zip
OpenCV 2.4.0

Mac OSX Lion

Please provide any additional information below.

While debugging I grabbed the pixel of the top left of the CvRect, to examine 
it, and received the following:

frame BGRA = {99,78,83,255}
image BGRA = {78,83,0,255}

these results were consistent no matter how long I ran it for. It looks like 
the G channel has become the B channel, the R has become the G, and the B has 
disappeared, making the new R 0.

Original issue reported on code.google.com by thomasdu...@gmail.com on 20 Jul 2012 at 1:06

GoogleCodeExporter commented 9 years ago
OpenCV does not specify any B, G, R, or A channel for IplImage. How do you 
obtain those values?

Original comment by samuel.a...@gmail.com on 20 Jul 2012 at 4:34

GoogleCodeExporter commented 9 years ago
I converted the IplImage into a BufferedImage, and extracted the pixel data 
32-bit integer from that, and split into 4x bytes, these were the BGRA 
components. For the IplImage that was the destination from cvCopy, the R 
component was always 0, and the other components were shifted as I specified in 
the original post.

Original comment by thomasdu...@gmail.com on 21 Jul 2012 at 11:54

GoogleCodeExporter commented 9 years ago
Ok, so could you provide the code for that?

Original comment by samuel.a...@gmail.com on 21 Jul 2012 at 12:32

GoogleCodeExporter commented 9 years ago
How did you "convert the IplImage into a BufferedImage"?

If I can't reproduce the problem here, I won't be able to fix this issue...

Original comment by samuel.a...@gmail.com on 15 Sep 2012 at 5:01

GoogleCodeExporter commented 9 years ago
I've just tried this out and it works perfectly fine for me:
    CvRect face = new CvRect(cvGetSeqElem(faces, i));
    cvSetImageROI(frame, face);
    IplImage image = cvCreateImage(cvGetSize(frame), frame.depth(), frame.nChannels());
    cvCopy(frame, image);
    frame.showImage(image.getBufferedImage());
    cvResetImageROI(frame);
If you can't explain what the problem is more clearly, I will be forced to mark 
this issue as "invalid"...

Original comment by samuel.a...@gmail.com on 7 Oct 2012 at 12:50

GoogleCodeExporter commented 9 years ago
Given the lack of feedback, I'm guessing whatever the problem was has been 
resolved, but please let me know if this isn't the case.

Original comment by samuel.a...@gmail.com on 5 Nov 2012 at 11:33