OpenCV视频未显示全尺寸

发布于 2025-02-12 02:57:58 字数 800 浏览 1 评论 0原文

我的问题是 opencv运行,并显示我的视频的原始大小(似乎OpenCV缩小了视频略微缩小),从而影响了我感兴趣的区域。

OpENCV如何显示我的视频的确切尺寸?以下是我的代码和视频原始大小的差异以及OpenCV显示的内容。

代码:

import cv2
cap = cv2.VideoCapture("video_link")
while True:
   ret, frame = cap.read()
   if not ret:
      break
   cv2.imshow("frame", frame)
   key = cv2.waitKey(1)
   if key == 27:
      break
cap.release()
cv2.destroyWindow()

原始大小:

“在此处输入图像描述”

openCV视频输出大小:

”在此处输入图像描述”

My problem is opencv runs and show my video not in its original size (seems OpenCV shrinks the video little bit), effecting my region of interest.

How can OpenCV show the exact orginal size of my video? Below is my code and the difference of the video original size and what OpenCV display.

Code:

import cv2
cap = cv2.VideoCapture("video_link")
while True:
   ret, frame = cap.read()
   if not ret:
      break
   cv2.imshow("frame", frame)
   key = cv2.waitKey(1)
   if key == 27:
      break
cap.release()
cv2.destroyWindow()

Original size:

enter image description here

OpenCV Video output size:

enter image description here

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

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

发布评论

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

评论(1

旧伤还要旧人安 2025-02-19 02:57:58

尝试一下,祝你好运。手动输入相机提要的高度和宽度。(编辑:dShow仅在获胜中起作用,如果您有其他东西,请使用其他解决方案)

import cv2

video="videolink"
height=1080 #for some reason, ANYTHING else works for my HD camera for example 1079..
width=1920

cap = cv2.VideoCapture(video, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)

while cap.isOpened():
    success, image = cap.read()
    if not success:
      print("Ignoring empty camera frame.")
      # If loading a video, use 'break' instead of 'continue'.
      continue
    cv2.imshow('CameraFeed', image )
    if cv2.waitKey(5) & 0xFF == ord("q"):
      break
cap.release()

try this, good luck. Manually enter the height, and width of the camera feed.(edit: Dshow works only in WIN, if you have something else, use different solution)

import cv2

video="videolink"
height=1080 #for some reason, ANYTHING else works for my HD camera for example 1079..
width=1920

cap = cv2.VideoCapture(video, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)

while cap.isOpened():
    success, image = cap.read()
    if not success:
      print("Ignoring empty camera frame.")
      # If loading a video, use 'break' instead of 'continue'.
      continue
    cv2.imshow('CameraFeed', image )
    if cv2.waitKey(5) & 0xFF == ord("q"):
      break
cap.release()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文