选择区域OpenCV [英] Selecting a Region OpenCV

查看:72
本文介绍了选择区域OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是OpenCV的新手,我想选择视频/图像中的特定区域进行检测.以我为例,我想检测仅在道路上而不在停车场内的汽车.

I am new to OpenCV and I want to select a particular region in the video/image for detection. In my case I want to detect cars that are only in the road not in the parking lot.

推荐答案

好吧,选择汽车需要使用训练数据.但是选择ROI(感兴趣的区域)非常简单:

Well, selecting cars requires use of training data. But to select an ROI (region of interest) is fairly simple:

考虑img = cv2.imread(image)

在这种情况下,您可以在代码中的某处以这种方式指定区域:

In that case, somewhere in your code, you can specify a region this way:

sub_image = img[y:y+h, x:x+w]

一旦您指定了值,则将获得ROI,当然,不使用'x'或'y',其中h是高度,w是宽度.请记住,图像只是2D矩阵.

That will get the ROI once you specify the values, of course, not using 'x' or 'y', where h is the height and w is the width. Remember that images are just 2D matrices.

使用CascadeClassifier()从图像中选择汽车.在> 此处 中找到文档. OpenCV随附了培训数据,您可以使用这些培训数据以XML文件的形式进行分类.

Use CascadeClassifier() to select the car(s) from the image(s). Documentation is found here. OpenCV comes packed with training data you can use to make classifications in the form of XML files.

这篇关于选择区域OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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