OpenCV的:多米诺骨牌圆点/磁盘检测 [英] OpenCV: Dominoes circular spots/disks detection
问题描述
我开发一个Android应用程序的计算之中,看到的多米诺骨牌件-shown使用OpenCV进行Android的图片 - 的所有点的总和。
I am developing an Android app that calculates the sum of all points of the being-seen dominoes pieces -shown in picture- using OpenCV for Android.
现在的问题是,我无法找到一个方法来过滤其他轮廓,只计算点我在多米诺骨牌看到,我试图用Canny边缘寻找,然后使用HoughCircles,但没有结果,因为我没有岩石和HoughCircles绝对俯视探测正圆只:)
The problem is, I can't find a way to filtering other contours and counting only dots I see in the dominoes, I tried to use Canny edge finding then use HoughCircles, but with no result, as I don't have an absolute top view of the rocks and HoughCircles detect perfect circles only :)
下面是我的code:
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;
}
编辑:
我的轮廓,一个独特的功能后,门槛是他们是全黑的里面,反正是有,我可以计算平均色彩/亮度为给定的轮廓?
One unique feature of my contours after threshold is they're totally black from inside, is there anyway I could calculate the mean color/intensity for a given contour ?
推荐答案
有一个类似的问题和SO可能的解决方案,名为<一个href="http://stackoverflow.com/questions/4785419/detection-of-coins-and-fit-ellipses-on-an-image">Detection对图片硬币(和合适的椭圆)。在这里你会找到有关的OpenCV的功能有些recomendations fitEllipse
。
There is a similiar problem and possible solution on SO, titled Detection of coins (and fit ellipses) on an image. Here you will find some recomendations about opencv's function fitEllipse
.
您应该看看<一href="http://opencv.willowgarage.com/documentation/cpp/imgproc_structural_analysis_and_shape_descriptors.html#cv-fitellipse"相对=nofollow>这对OpenCV的函数的详细信息 fitEllipse
。
You should take a look at this for more info on opencv's function fitEllipse
.
此外,检测的图像只有黑色的元素,你可以使用HSV颜色模型,发现只有黑色的颜色。您可以这里找到一个解释。
Also, to detect only black elements in an image, you can use HSV color model, to find only black colors. You can find an explanation here.
这篇关于OpenCV的:多米诺骨牌圆点/磁盘检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!