边缘检测后从各个方向裁剪图像 [英] Crop Image from all sides after edge detection

查看:111
本文介绍了边缘检测后从各个方向裁剪图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenCV的新手。我想从图像中提取主要对象。所以,我已经在图像上应用了Canny以获得主对象周围的边缘并得到以下输出:

I am new to OpenCV. I want to extract the main object from an image. So, I have applied Canny on the image to get the edges around the main object and got the following output :

以下是在Python中使用OpenCV获取此代码的代码:

Here is the code to get this using OpenCV in Python:

img = cv2.imread(file)
cv2.imshow("orig", img)
cv2.waitKey(0)
img = cv2.blur(img,(2,2))
gray_seg = cv2.Canny(img, 0, 50)

现在,我希望获得下面的图像作为最终输出只有图像中的主要对象:

Now, I want to have the below image as the final output after getting only the main object in the image :

我想以优化的方式进行,因为我必须处理更多的250万张图像。
任何人都可以帮我这个吗?

I want to do it in an optimized manner because I have to process more that 2.5 million images. Can anyone help me with this?

推荐答案

rect函数应该提供你需要的功能。下面是一个如何使用它的例子。

The rect function should provide the functionality you need. An example of how to use it can be seen below.

cv::Mat image(img);
cv::Rect myROI(posX, posY, sizeX, sizeY);   
cv::Mat croppedImage = image(myROI);

这是用c ++编写的,但应该能够找到一个等价的python。

This is writing in c++ but should be able to find a python equivalent.

我下面的链接提供更多信息
如何在OpenCV中裁剪CvMat?

The link below my provide more info How to crop a CvMat in OpenCV?

这篇关于边缘检测后从各个方向裁剪图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆