我在Android应用程序中使用OpenCV。我想让移动应用程序在矩形(例如收据形状的东西)在视图中时自动拍照。我正在使用Canny边缘检测,但是当我查找轮廓时,数组大小大于1500.显然,循环遍历所有轮廓并找到最大轮廓并不是最佳选择,所以我想知道是否可以筛选出最大通过api自动轮廓?OpenCV Java极限轮廓
我迄今为止代码:
ArrayList contours;
@Override
public Mat onCameraFrame(final CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
// Clear contours array on each frame
contours.clear();
// Get Grayscale image
final Mat gray = inputFrame.gray();
// Canny edge detection
Imgproc.Canny(gray, gray, 300, 1000, 5, true);
// New empty black matrix to store the edges captured
Mat dest = new Mat();
Core.add(dest, Scalar.all(0), dest);
// Copy the edge data over to the empty black matrix
gray.copyTo(dest);
// Is there a way to filter the size of contours so that not everything is returned? Right now this function is returning a lot of contours (1500 +)
Imgproc.findContours(gray, contours, hirearchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
return dest;
}
编辑 用户会拿着电话,我希望应用程序自动拍摄照片时的收据是在视图中。 Example receipt
可能是因为如果你提供了一些输入图像,那么可以建议一些比Canny更好的技术,因为canny用于检测边缘,使用canny结果检测物体不是一个明智的想法,可能会丢失噪声即使在调整参数之后,所以我建议你去使用颜色分割,就像事先知道接受者将要使用的颜色一样,并调整颜色限制的阈值一点以抵消输入图像中的亮度变化 – ZdaR
收据图像将是黑色和白色。我想要一种让相机从背景中检测收据并自动拍摄照片的方法。 –
如果这个人拿着虚假的空白纸,或者在背景中有一些其他白色物体会怎么样? – ZdaR