[英]cv2.Resize() not working after OpenCV compilation
So I wanted to test performance difference between python-opencv library and newest opencv compiled, on a raspberry pi 4 board.所以我想在树莓派 4 板上测试 python-opencv 库和最新编译的 opencv 之间的性能差异。 After this change
cv2.resize()
stopped working in my script and only outputs max resolution from my webcam.此更改后
cv2.resize()
停止在我的脚本中工作,仅从我的网络摄像头输出最大分辨率。 I also tried imutils library but without success.I tried using both:我也尝试过 imutils 库,但没有成功。我尝试同时使用:
cv2.CAP_PROP_FRAME_WIDTH
cv2.CAP_PROP_FRAME_HEIGHT
But I only get a resized window not frame但我只得到一个调整大小的窗口而不是框架
Additionally I get this error GStreamer warning:Cannot query video position: status=0, value=-1, duration=-1另外我收到这个错误 GStreamer 警告:无法查询视频位置:状态=0,值=-1,持续时间=-1
What have I missed?我错过了什么?
Update: Minimal code更新:最少的代码
import cv2
from imutils.video import FPS
cap = cv2.VideoCapture(0)
#cap.set(cv2.CAP_PROP_FRAME_WIDTH,960)
#cap.set(cv2.CAP_PROP_FRAME_HEIGHT,540)
fps = FPS().start()
font = cv2.FONT_HERSHEY_DUPLEX
while cap.isOpened():
ret, frame = cap.read()
small_frame = cv2.resize(frame, (0, 0), fx=0.75, fy=0.75)
fps.update()
fps.stop()
cv2.putText(small_frame,"FPS {:.1f}".format(fps.fps()),
(10,30),font, 1.0, (255, 255, 255), 1)
cv2.imshow("Frame",small_frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
if key == ord('p'):
cv2.waitKey(-1)
cap.release()
cv2.destroyAllWindows()
you are using scale and dimentions 0 togheter try this:你正在使用比例和维度 0 一起试试这个:
import cv2
img = cv2.imread('/home/img/python.png', cv2.IMREAD_UNCHANGED)
print('Original Dimensions : ',img.shape)
scale_percent = 60 # percent of original size
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
# resize image
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
print('Resized Dimensions : ',resized.shape)
cv2.imshow("Resized image", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.