我很难找到使用OpenCV在Python中以特定(通常非常小)的角度围绕特定点旋转图像的示例.
这是我到目前为止所做的,但它会产生一个非常奇怪的结果图像,但它有点旋转:
def rotateImage( image, angle ):
if image != None:
dst_image = cv.CloneImage( image )
rotate_around = (0,0)
transl = cv.CreateMat(2, 3, cv.CV_32FC1 )
matrix = cv.GetRotationMatrix2D( rotate_around, angle, 1.0, transl )
cv.GetQuadrangleSubPix( image, dst_image, transl )
cv.GetRectSubPix( dst_image, image, rotate_around )
return dst_image
Run Code Online (Sandbox Code Playgroud) 我使用了canny边缘检测,我在我试图处理的图像上找到了轮廓.我想找到五个最大的轮廓,然后看看图像中五个最大轮廓内是否有轮廓.这可能吗?我是OpenCV的新手.
我知道这是重复的帖子,但仍然坚持执行。我遵循互联网上的一些指南,了解如何在 OpenCV 和 Java 中检测图像中的文档。我想出的第一个方法是在预处理一些图像处理(如模糊、边缘检测)后使用 findContours,在获得所有轮廓后,我可以找到最大的轮廓并假设这是我正在寻找的矩形,但它失败了在某些情况下,例如文件没有被完全取走,就像遗漏了一个角落。在尝试了几次和一些新的处理但根本不起作用之后,我发现 HoughLine 变换变得更容易了。从现在开始,我在图像中拥有所有线条,但仍然不知道接下来要做什么来定义我想要的兴趣矩形。这是我到目前为止的实现代码: 方法 1:使用 findContours
Mat grayImage = new Mat();
Mat detectedEdges = new Mat();
// convert to grayscale
Imgproc.cvtColor(frame, grayImage, Imgproc.COLOR_BGR2GRAY);
// reduce noise with a 3x3 kernel
// Imgproc.blur(grayImage, detectedEdges, new Size(3, 3));
Imgproc.medianBlur(grayImage, detectedEdges, 9);
// Imgproc.equalizeHist(detectedEdges, detectedEdges);
// Imgproc.GaussianBlur(detectedEdges, detectedEdges, new Size(5, 5), 0, 0, Core.BORDER_DEFAULT);
Mat edges = new Mat();
// canny detector, with ratio of lower:upper threshold of 3:1
Imgproc.Canny(detectedEdges, edges, this.threshold.getValue(), this.threshold.getValue() * 3, 3, true);
// …
Run Code Online (Sandbox Code Playgroud)