如何在OpenCV相机捕获中动态调整帧大小和显示帧区域?

发布于 2025-01-16 20:05:47 字数 175 浏览 1 评论 0原文

我试图建立一个模型,可以根据检测动态调整 OpenCV 中相机捕获的显示区域。我找到了调整帧和分辨率大小的方法,但是如果我想专注于整个捕获的特定区域该怎么办?我怎样才能做到这一点?

我尝试了 cv2.resize() 方法和 cap.set() 方法,它们分别更改了帧大小和分辨率,但我无法使提要聚焦于整个捕获帧的特定区域

I was trying to build a model that can dynamically adjust the display region of the camera capture in OpenCV according to the detections. 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掌心的温暖 2025-01-23 20:05:47

如果我的想法是正确的,您想根据您的检测来裁剪图像的一部分坐标。 OpenCV 用数组表示图像,因此示例图像:

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)

在此处输入图像描述

然后您只需通过索引访问数组的部分并获取其裁剪部分:

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

在此处输入图像描述

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:

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)

enter image description here

Then you just access array's part by indexing and get its cropped part:

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

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文