Oma*_*ker 8 java android opencv
我正在开发一款Android应用程序,用于计算使用OpenCV for Android的图片中所显示的多米诺骨牌片的所有点数的总和.

问题是,我找不到一种方法来过滤其他轮廓并只计算我在多米诺骨牌中看到的点,我试图使用Canny边缘找到然后使用HoughCircles,但没有结果,因为我没有绝对的顶部岩石和HoughCircles的视图只检测完美的圆圈:)
这是我的代码:
public Mat onCameraFrame(Mat inputFrame) {
inputFrame.copyTo(mRgba);
Mat grey = new Mat();
// Make it greyscale
Imgproc.cvtColor(mRgba, grey, Imgproc.COLOR_RGBA2GRAY);
// init contours arraylist
List<MatOfPoint> contours = new ArrayList<MatOfPoint>(200);
//blur
Imgproc.GaussianBlur(grey, grey, new Size(9,9), 10);
Imgproc.threshold(grey, grey, 80, 150, Imgproc.THRESH_BINARY);
// because findContours modifies the image I back it up
Mat greyCopy = new Mat();
grey.copyTo(greyCopy);
Imgproc.findContours(greyCopy, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_NONE);
// Now I have my controus pefectly
MatOfPoint2f mMOP2f1 = new MatOfPoint2f();
//a list for only selected contours
List<MatOfPoint> SelectedContours = new ArrayList<MatOfPoint>(400);
for(int i=0;i<contours.size();i++)
{
if(here I should put a condition that distinguishes my spots, eg: if contour inside is black and is a black disk)
{
SelectedContours.add(contours.get(i));
}
}
Imgproc.drawContours(mRgba, SelectedContours, -1, new Scalar(255,0,0,255), 1);
return mRgba;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我的轮廓在阈值之后的一个独特特征是它们从内部完全是黑色的,无论如何我可以计算给定轮廓的平均颜色/强度?
在SO上存在类似的问题和可能的解决方案,标题为在图像上检测硬币(和拟合椭圆).在这里,您将找到有关opencv功能的一些建议fitEllipse.
你应该看看这个有关opencv函数的更多信息fitEllipse.
此外,要仅检测图像中的黑色元素,可以使用HSV颜色模型,仅查找黑色.你可以在这里找到解释.
| 归档时间: |
|
| 查看次数: |
3192 次 |
| 最近记录: |