Ask Your Question
2

Crop Image using hough circle

asked 2013-08-13 13:03:29 -0500

lenteken gravatar image

updated 2013-08-14 05:27:37 -0500

I want to crop the image using hough circle. I saw in some forum that they used Rect in ROI but it is not what I need because I want to crop the iris from the eye. Is there any possible solution?

edit retag flag offensive close merge delete

Comments

I personally havent used hough circles, so I dont exactly know how they work/look like internally. But the general idea for your task is like here I guess: http://stackoverflow.com/questions/10632195/define-image-roi-with-opencv-in-c Although you will need to convert it to c++ style. The important thing is to create a Mask that represents your circle and use this mask with bitwise_and(img, img, dst_img, mask)

Moster gravatar imageMoster ( 2013-08-13 13:35:37 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
6

answered 2013-08-13 17:50:01 -0500

Basically, the idea is to draw the detect circle filled. Therefore, you have a mask. After, just copy your original image into the destination.

// center and radius are the results of HoughCircle
// mask is a CV_8UC1 image with 0
cv::Mat mask = cv::Mat::zeros( img.rows, img.cols, CV_8UC1 );
circle( mask, center, radius, Scalar(255,255,255), -1, 8, 0 ); //-1 means filled
img.copyTo( dst, mask ); // copy values of img to dst if mask is > 0.

You will find the doc here: circle and CopyTo

You could also apply a ROI before copying image to reduce their size:

cv::Mat roi( img, cv::Rect( center.x-radius, center.y-radius, radius*2, radius*2 ) );
edit flag offensive delete link more

Comments

How can you do it by using cv2?

akif gravatar imageakif ( 2015-12-08 04:59:47 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2013-08-13 13:03:29 -0500

Seen: 9,972 times

Last updated: Aug 14 '13