YUV420888 to Grayscale Image (cvtColor ENUM) [closed]
I looked around for a Conversion of the YUV420 Image to a Grayscale Image and found this Issue in the DevZone
According to this, there is already a YUV to Grayscale Conversion enum for cvtColor()
.
But, as also mentioned in the issue, the enums are not good documented. My Question now is, which of these Enums do I have to use if I want to convert a packed YUV ByteBuffer
into a Grayscale ByteBuffer
or Image
/cv::Mat
?
Thanks for your attentiveness.
So I found the following ENUM CV_YUV2GRAY_420
is that the one I need?
I tried the enum above with this test:
I capture a Frame in Android from my Preview in YUV_420_888
Format. I pass that to a function which packs the 3 Plane buffers into one ByteBuffer
and put it into a byte[]
:
Image img = params[0];
ByteBuffer dstBuffer = ByteBuffer.allocateDirect(img.getWidth() * img.getHeight() * ImageFormat.getBitsPerPixel(img.getFormat()) / 8);
getDataFromImage(img, dstBuffer);
byte[] data = new byte[dstBuffer.remaining()];
dstBuffer.put(data);
Then I'll pass that byte[]
to JNI and use cv::Mat(height + height/2, width, CV_8UC1, imageData)
to create a Mat with the data (the byte[]
was converted to a unsigned char*
) Now I do this:
cv::Mat img(height + height/2, width, CV_8UC1, imageData)
cv::Mat gry;
cv::cvtColor(img, gry, CV_YUV2GRAY_420, 1)
But it seems, that the result is wrong, because I can't extract any Features out of this grayscale Image.