我是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
发布评论