JenyaKirmiza / javacv

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

cvSetImageROI() and cvWarpAffine() made false color image #327

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Sorry for my English : )

What steps will reproduce the problem?
1. get image from camera preview
2. crop and rotate image
3. use FFmpegFrameRecorder to create video

What is the expected output? What do you see instead?
Vine like video

What version of the product are you using? On what operating system?
javacv-0.5 on android

Please provide any additional information below.
I want to create Vine liked app that adapted from sample RecordActivity.java, 
everything is ok but when i add process crop and rotate image it's produce 
false color image, as i know the crop problem is cvSetImageROI() (remark it 
color is ok!), please see Attach file, thanks!.

Original issue reported on code.google.com by geuma...@gmail.com on 14 Jun 2013 at 11:47

Attachments:

GoogleCodeExporter commented 9 years ago
Just try to

IplImage imageBGR = IplImage.create(imageWidth, imageHeight, IPL_DEPTH_8U, 3);
                    cvCvtColor(image,imageBGR,CV_YUV2BGR_NV21);

but video is greenish.

Original comment by geuma...@gmail.com on 14 Jun 2013 at 12:39

GoogleCodeExporter commented 9 years ago
cvSetImageROI() won't work on planar images, that's normal. You'll need to 
convert that to RGB beforehand.

How do you create the `image` that you use in 
cvCvtColor(image,imageBGR,CV_YUV2BGR_NV21); ?

Original comment by samuel.a...@gmail.com on 16 Jun 2013 at 2:02

GoogleCodeExporter commented 9 years ago
Thanks : ),

this way I'm create the 'image'

IplImage image = IplImage.create(imageWidth, imageHeight*3/2, IPL_DEPTH_8U, 2);

Original comment by geuma...@gmail.com on 17 Jun 2013 at 2:21

GoogleCodeExporter commented 9 years ago
Just found this solution

http://stackoverflow.com/questions/12644627/android-javacv-create-iplimage-from-
camera-to-use-with-colorhistogram

It's worked!, but this is the best way?

Many thanks!

Original comment by geuma...@gmail.com on 17 Jun 2013 at 3:14

GoogleCodeExporter commented 9 years ago
Thanks for pointing me back to my answer :) But it was not correct. I've edited 
to the following "best way", which should work, but again not tested:
    IplImage imageYUV = IplImage.create(imageWidth, imageHeight * 3 / 2, IPL_DEPTH_8U, 2);
    IplImage imageBGR = IplImage.create(imageWidth, imageHeight, IPL_DEPTH_8U, 3);
    cvCvtColor(imageYUV, imageBGR, CV_YUV2BGR_NV21);
Let me know if you have any problems with that, and please ask your questions 
on the mailing list next time if possible, thanks you!

Original comment by samuel.a...@gmail.com on 22 Jun 2013 at 4:15

GoogleCodeExporter commented 9 years ago
Thanks!

but it's not work, just greenish like Attach file.

Original comment by geuma...@gmail.com on 25 Jun 2013 at 3:36

Attachments:

GoogleCodeExporter commented 9 years ago
What code are you using?

Original comment by samuel.a...@gmail.com on 29 Jun 2013 at 1:25

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
decode yuv420sp to rgb before cropImage and rotateImage..
cvSetImageROI not clearly work on yuv format image..

...
public void onPreviewFrame(byte[] data, Camera camera) {
    ...
    int[] _temp = new int[imageWidth * imageHeight];
    decodeYUV420SP(_temp, data, imageWidth, imageHeight);
    IplImage image = IplImage.create(imageWidth, imageHeight, IPL_DEPTH_8U, 4);
    image.getIntBuffer().put(_temp);
    cvSetImageROI(image, new CvRect(...));
    ...
}

...
public static void decodeYUV420SP(int[] rgb, byte[] yuv420sp, int width, int 
height) {
    int frameSize = width * height;
    for (int j = 0, yp = 0; j < height; j++) {
        int uvp = frameSize + (j >> 1) * width, u = 0, v = 0;
        for (int i = 0; i < width; i++, yp++) {
            int y = (0xff & ((int) yuv420sp[yp])) - 16;
            if (y < 0) y = 0;
            if ((i & 1) == 0) {
                v = (0xff & yuv420sp[uvp++]) - 128;
                u = (0xff & yuv420sp[uvp++]) - 128;
            }
            int y1192 = 1192 * y;
                int r = (y1192 + 1634 * v);
            int g = (y1192 - 833 * v - 400 * u);
            int b = (y1192 + 2066 * u);
            if (r < 0) r = 0; else if (r > 262143) r = 262143;
            if (g < 0) g = 0; else if (g > 262143) g = 262143;
            if (b < 0) b = 0; else if (b > 262143) b = 262143;
            rgb[yp] = 0xff000000 | ((b << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((r >> 10) & 0xff);
        }
    }
}

Original comment by g.wig...@gmail.com on 29 Jul 2013 at 2:38

GoogleCodeExporter commented 9 years ago
No it doesn't unfortunately... We need to convert it to RGB first.

Original comment by samuel.a...@gmail.com on 15 Aug 2013 at 3:19

GoogleCodeExporter commented 9 years ago
Is that solved?

Original comment by omur.ir...@gmail.com on 21 Oct 2013 at 1:27

GoogleCodeExporter commented 9 years ago
Converting it to RGB didn't solve the problem, still green pictures. I'm 
looking for a solution.

Original comment by omur.ir...@gmail.com on 21 Oct 2013 at 5:18

GoogleCodeExporter commented 9 years ago
@omur Can you provide the few lines of code you are using? Thanks

Original comment by samuel.a...@gmail.com on 3 Nov 2013 at 1:56

GoogleCodeExporter commented 9 years ago
hi , 

how did you find the solution for same, 
Can you give me some hint

Thanks

Original comment by Bindal...@gmail.com on 25 Nov 2013 at 9:33

GoogleCodeExporter commented 9 years ago
Guys, if you are having a problem with a piece code, we cannot solve the 
problem if you do not provide the piece of code in question! Please copy/paste 
the piece of code you are executing and that isn't working as it should, thank 
you.

Original comment by samuel.a...@gmail.com on 26 Nov 2013 at 6:04