Problem creating Mat from camera buffers (edited)
Latest update
So I've made a few changes and would like to list them and the results.
The camera buffer is in 32 bit ARGB. I changed the type in the Mat initialization to CV_32FC4. When I call
cv::blur(src,dest,Size(5,5));
I am seeing a red screen - lending me to believe the ARGB format is not working with the Mat.
So I guess the question boils down to, how do I format ARGB to work with OpenCV Mat?
Original question
Hey guys,
So I'm creating a Mat from camera buffers that I'm receiving like so:
cv::Mat src = cv::Mat(cv::Size(img_height, img_width),CV_8UC4);
memcpy(src.ptr(), (void*) img_buffer,img_height * img_width * 4);
This works fine.
But when I try to do any operation on this, I get weird output.
For example,
cv::blur(src,src,Size(5,5));
results in the expected output (blurred) but divided into 5 "columns".
Similarly, if I try
cv::blur(src,src,Size(3,3));
I get 3 such columns.
Same with other operations - Gaussian blur, erode etc
Only other operation I have tested that works fine without a problem is clone().
Can anyone hazard a guess as to why this might be happening?
I'm working on a device which does not have a proper port of OpenCV so all OS related tasks(reading and writing images) are being done by hand.
=====UPDATE======
So I've been experimenting a little.
I can make calls such as
cv::medianBlur(inter,dest,3);
and there is output (albeit distorted as described above). But when I do something like
cv::cvtColor(inter, dest, COLOR_RGBA2RGB);
I'm getting segfault errors. Is there a fundamental difference in how these functions work that may be indicative of the problem?
Post an image of your srsc before and after blurring (screencapture an
imshow()
). The problem seems to be the memory layout of your original bufferHey @sammy what is an srsc? Can you also see the update I've made, if that gives any clue?
The camera buffer that is coming in is 32 bit ARGB data. I thought OpenCV worked with RGB? The camera buffer can also come in in NV12. What would be better to handle?
@samir22, i'm just curious, from what kind of device do you get 32 bit ARGB data ? cvtColor() can convert argb as well as yuv to bgr (not sure about nv12, but that's some kind of yuv, iirc)
@samir22 I wanted to write
src
- your source image.@berak, I tried using cvtColor but it kept segfaulting. Please see the update to my question.
@samir22, tried cv::cvtColor(inter, dest, COLOR_RGB2RGBA); and back, no problem here.
also blur() works fine on rgba data for me. no colums or such.
i think sammy is right, must be something with the memory layout of your original buffer.
since you said, you're doing most of the i/o stuff yourself, might be helpful, to show some bits of code related to that
Btw, you problem is here: CV_32FC4 is a matrix of floats. But you have probably integers, so CV_32UC4 is the way to go