2014-11-08 134 views
-1

我想裁剪图像中的圆形状。 我有一个灰度输入图像。 在这张图片中有一个圆形。我需要它。 如何在Android上使用Open CV进行操作?如何裁剪圆形图像openvc android

输入图像:

enter link description here http://www.photo-dictionary.com/photofiles/list/2264/2960temperature_gauge.jpg

Bitmap bmpProces = BitmapFactory.decodeFile(path+inpuImage); 
Mat imageMat = new Mat (bmpProces.getHeight(), bmpProces.getWidth(), CvType.CV_8U); 
Bitmap myBitmap32 = bmpProces.copy(Bitmap.Config.ARGB_8888, true); 
Utils.bitmapToMat(myBitmap32, imageMat); 

回答

0

你必须创建一个面具,填充圈,以及在根据目标的坐标,并使用CopyTo在mask.Then来抽取目标的圆形区域,您可以在面具Mat.You可以看到示例代码和一些更多的细节here。有一个代码段,您可以将其转换为Java并使用它:

// 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.