Ask Your Question
0

Label Contours

asked 2016-04-06 04:26:25 -0600

ClementD gravatar image

updated 2016-04-07 06:22:23 -0600

Hello,

I post this message because in need help with a project.

I have a binary image that containt object i want to detect ( obtained with a backgroundSubtractor)

Once detected,I want to give each object a label on an other image (the label Image). Then on the next image ( because i use a video ), I want to know which object has already been labeled using the last label image.

I use "findContours" to get all contours;

my Question is : Is there any method or function that could help me to get all pixels of with a given value (for example 3 )? I would like a function like "cv::findNonZero " but more specified like "findNumberPixel".

By waiting you answer i start to try create my own tools.

Thanking you in advance

Solution : (Thanks to LBerger ) Using InRange with all my values allows me to detect the label i want DrawContour with filled option allows me to draw my labels

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-04-06 04:41:05 -0600

LBerger gravatar image

updated 2016-04-06 04:44:54 -0600

you can use == or inRange

Mat im=imread("lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat dst;

dst = im==3;
imshow("== 3 ",dst);
inRange(im,120,140,dst);
imshow("inrange [120,1420]",dst);
waitKey();

mat dst can be used after a mask

edit flag offensive delete link more

Comments

1

Thanks you , i will use inRange(img , myValue, myValue, binaryImage) then get my new contour with find contours. Is there a way to know how many differents values i had in my range?

ClementD gravatar imageClementD ( 2016-04-06 04:50:04 -0600 )edit

Do you want connected component of your binary image?

LBerger gravatar imageLBerger ( 2016-04-06 05:36:25 -0600 )edit

If i use inRange (img, 1, 2, imageOut), i want to know where are the 1 and where are the 2

ClementD gravatar imageClementD ( 2016-04-06 05:44:44 -0600 )edit

I don't think it's possible using opencv function to have a vector of point. if you use inRange (img, 1, 2, imageOut) pixels with values and 1 will be mixed in your results.

You should think your problem not like a pixel problem but a Mat problem. results are imageOut and you make many things with this mask imageOut.

LBerger gravatar imageLBerger ( 2016-04-06 06:48:03 -0600 )edit

Yes i change my point of view. how can i draw inside contours?

i tried this but it failed:

cv::polylines(img, contours.at(i), true, cv::Scalar(255,255,255), CV_FILLED);

I found it:

cv::fillConvexPoly  (img, contours.at(i), cv::Scalar(255, 0, 0));
ClementD gravatar imageClementD ( 2016-04-06 06:58:48 -0600 )edit

if you want fill your contour use DrawContour like this

LBerger gravatar imageLBerger ( 2016-04-06 07:05:45 -0600 )edit

Oh ok Thanks you a lot. your helped me very fastly. My probleme is solved.

ClementD gravatar imageClementD ( 2016-04-06 07:08:46 -0600 )edit

@ClementD I just gave you enough karma to accept the solution. Could you do so?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-07 06:23:22 -0600 )edit
1

@StevenPuttmans Hello , how can i accept it?

ClementD gravatar imageClementD ( 2016-04-07 06:41:59 -0600 )edit

By pressing the okay button under the number next to the answer!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-04-07 07:34:15 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-06 04:26:25 -0600

Seen: 3,431 times

Last updated: Apr 07 '16