Ask Your Question
0

Help with cvCreatMat

asked 2013-03-08 17:43:27 -0600

So, I'm a new openCV user, and I could use some help. Below is some code that I'm trying to write for a blob detection program, not using the blob.h library. My goal is to create a new mat one pixel bigger than the original mat then copy the data in to the new one so that there is one pixel lining the edge. Then I can start going through the data and not have to worry about the edges. But I'm having a problem with getting the new structure created and the data in it. Can anyone help?

Mat img_src, img_dst;

CvMat *img_onebigger;

void BlobDetection(Mat image) {

////// Number of new rows and new columns are 1/2 original

int cols = image.cols;

int rows = image.rows;

uchar* data = image.data;

int label_id = 1;

int r, c;

////// Original step size (number of values per row) of image

int step = image.step;

int current_pixel = image.data[r*step + c];

img_onebigger = cvCreateMat(rows+1, cols+1, CV_32FC1);

cvCreateData(img_onebigger);

for(r=1; r < rows; r++){

  for(c=1; c<cols; c++){

    img_onebigger->data[r*step+c] = image.data[r*step+c];
    }
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-03-08 17:58:21 -0600

awknaust gravatar image

updated 2013-03-08 17:59:33 -0600

You are mixing the OpenCV C API (CvMat*) and OpenCV C++ (Mat), something you do not really want to do, at least not like this. If you want to create an image with a 1pixel extra border, its easy theres even a function to do it directly

edit flag offensive delete link more

Comments

So, I get that. And its fixed. I used copyCreateBorder, and it compiles. When I run it I get a segmentation fault. The same ones I was getting with the previous code.

drew.winners gravatar imagedrew.winners ( 2013-03-08 19:50:51 -0600 )edit

What exactly is the error? did you use the example code they give in the documentation?

awknaust gravatar imageawknaust ( 2013-03-09 19:47:05 -0600 )edit

Question Tools

Stats

Asked: 2013-03-08 17:43:27 -0600

Seen: 487 times

Last updated: Mar 08 '13