简体   繁体   English

OpenCV摄像头抓拍时如何动态调整边框尺寸和显示边框区域?

[英]How can I dynamically adjust the frame size and the display frame region in OpenCV camera capture?

I was trying to build a model that can dynamically adjust the display region of the camera capture in OpenCV according to the detections.我试图构建一个 model,它可以根据检测动态调整 OpenCV 中摄像头捕获的显示区域。 I found frame and resolution resizing methods, but what if I want to focus on a particular region of the entire capture?我找到了调整帧和分辨率大小的方法,但是如果我想专注于整个捕获的特定区域怎么办? How can I do that?我怎样才能做到这一点?

I tried the cv2.resize() method, and the cap.set() method, which changed the frame size and the resolution respectively, but I could not make the feed to get focused on a particular region of the entire captured frame我尝试了 cv2.resize() 方法和 cap.set() 方法,它们分别改变了帧大小和分辨率,但我无法使提要聚焦于整个捕获帧的特定区域

If I've got your idea correct, you want to crop a part of an image with coordinates based on your detection.如果我的想法是正确的,您希望根据您的检测裁剪带有坐标的图像的一部分。 OpenCV represents images with arrays, so with exaple image: OpenCV 表示具有 arrays 的图像,因此示例图像:

import cv2
import matplotlib.pyplot as plt


img = cv2.imread('/content/drive/MyDrive/1.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)

print(img.shape)

在此处输入图像描述

Then you just access array's part by indexing and get its cropped part:然后您只需通过索引访问数组的部分并获取其裁剪部分:

plt.imshow(img[250: 450, 250: 450])

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM