Ask Your Question
1

contour look strange

asked 2018-04-24 01:10:32 -0600

open_ranger gravatar image

I try to convert contour into Pixel and the output look funny.

void extractContour(Mat input){
    Mat temp=Mat::zeros(input.rows,input.cols,CV_8U);
    vector<vector<Point>> contour;
    findContours(input,contour,RETR_EXTERNAL,CHAIN_APPROX_NONE);
    for(int i=0;i<contour[0].size();i++){
    temp.at<Vec3b>(contour[0][i])=255;
    cout<<contour[0][i]<<"\t";
    }
    cout<<endl;
    imwrite("/home/wxh/Desktop/Photo/1.bmp",temp);
}

image description

Any idea why is it deformed and in the wrong position?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2018-04-24 01:15:56 -0600

berak gravatar image

your temp Mat is CV_8UC1, so you have to use:

temp.at<uchar>(contour[0][i])=255;

in general, please try to avoid per-pixel access, and use builtin functions, like drawContours() here.

edit flag offensive delete link more

Comments

1

☆⌒(*^-゜)v THX!!

open_ranger gravatar imageopen_ranger ( 2018-04-24 01:36:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-04-24 01:10:32 -0600

Seen: 186 times

Last updated: Apr 24 '18