Ask Your Question
1

mat from buffer

asked 2015-09-22 03:59:05 -0500

Aj-611 gravatar image

I try to capture video from frame grabber. What I did is I point raw data from buffer into Mat as follow:

myMat = Mat(Size (x, y), CV_8UC1, ImaqBuffer); Image below (picture 1) show what I got from myMat (image after change to Mat), compare to what I'd supposed to get (the image save direct from buffer) (picture 2).

image description

image description

How can I solve this?

edit retag flag offensive close merge delete

Comments

I suppose it is CV_8UC3

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-09-22 04:14:10 -0500 )edit

Take a look documentation

void process_video_frame(const unsigned char* pixels,
                         int width, int height, int step)
{
    Mat img(height, width, CV_8UC3, pixels, step);
    GaussianBlur(img, img, Size(7,7), 1.5, 1.5);
}

also look for an example usage https://github.com/Itseez/opencv/pull...

sturkmen gravatar imagesturkmen ( 2015-09-22 04:57:16 -0500 )edit

But why CV_8UC3? Since it is a grayscale image, not color image.

Aj-611 gravatar imageAj-611 ( 2015-09-23 00:13:54 -0500 )edit
1

Check the image dimensions, step and data type (really 8 bit unsigned?), or maybe it is a color image with all the same values for r,g,b.

boaz001 gravatar imageboaz001 ( 2015-09-23 02:30:22 -0500 )edit

It is a color image that has just gray values. Did you save it on 1 channel?

@sturkmen: I do not understand the & -4 from the step part. Can you explain it please? :)

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-09-23 02:37:39 -0500 )edit

also i don't know :) there is a problem when saving some images by CTRL + S. i tried to solve taking reference

sturkmen gravatar imagesturkmen ( 2015-09-23 04:46:57 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-09-28 02:37:30 -0500

Aj-611 gravatar image

I found the solution. Data type from buffer actually CV_16SC1. However, imshow will only shows gray windows. So, I need to convert from CV_16SC1 into CV_8UC1. Thanks to all for helping!

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2015-09-22 03:59:05 -0500

Seen: 1,122 times

Last updated: Sep 28 '15