Ask Your Question

goodFeaturesToTrack returns 2 channel image and can't be imshowed

asked 2015-05-01 04:20:06 -0600

OpenCVFan19 gravatar image


I'm using goodFeaturesToTrack() method to locate corners from an image. However when I try to view the image, using imshow(), I get an error:

OpenCV Error: Bad number of channels (Source image must have 1, 3 or 4 channels) in cvConvertImage

Here is the code:

Mat outPutImage;
goodFeaturesToTrack(src_gray, outPutImage, 20, 0.5, 500);
imshow("Output", outPutImage);

goodFeaturesToTrack takes in only a 1 channel image and outputs a 2 channel image. How can I convert the 2 channel to 3 channel or is there an alternative for imshow?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-05-01 05:02:13 -0600

berak gravatar image

updated 2015-05-01 05:32:57 -0600

the output is not an image, but a list of 2d points. please see docs

Mat gray; cvtColor(ocv,gray,COLOR_BGR2GRAY);

vector<Point> gftt;
goodFeaturesToTrack(gray, gftt, 100, 0.1, 5);

for (size_t i=0; i<gftt.size(); i++)
    circle(ocv, gftt[i], 4, Scalar(200,0,0));

imshow("Output", ocv);

image description image description

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-05-01 04:20:06 -0600

Seen: 1,818 times

Last updated: May 01 '15