Reputation: 290
I am new to image processing, In my application , i want to save the detected circles as a new image , The following code has been used to store the detected circle.
new CircleF(new PointF(circles[0].Center.X + grayframeright_1.ROI.Left, circles[0].Center.Y + grayframeright_1.ROI.Top), circles[0].Radius);
Are there any methods available in emgu cv / open cv to save the circle as a new Image?
Please help me to figure this out, Code samples would be useful.
Thanks in advance
Upvotes: 1
Views: 2478
Reputation: 1599
If I understood correctly what you want is to have a mask that covers the area of the circle and apply this mask to the image.
For this you need a mask:
//img is the image you applied Hough to
Image<Gray, byte> mask = new Image<Gray, byte>(img.Width, img.Height);
mask will be a black image. You need to draw in this image the area of the circle:
CvInvoke.cvCircle(mask.Ptr, center, radius, new MCvScalar(255, 255, 255), -1, Emgu.CV.CvEnum.LINE_TYPE.CV_AA, 0);
//-1 is to fill the area
now mask will have a white circle with center in the point center
and radius radius
. Doing an AND operation between the original image and this mask will copy to a new image only the points where the mask is white (where the circle is drawn).
Image<Bgr, byte> dest = new Image<Bgr, byte>(img.Width, img.Height);
dest = img.And(img, mask);
You can save dest as an usual image now
dest.Save("C:/wherever...");
If the image is too big and the circle too small, you can reduce the image size setting the image ROI before saving it to be an area around the circle:
dest.ROI = new Rectangle(center.X - radius, center.Y - radius, radius * 2, radius * 2);
Upvotes: 3