简体   繁体   中英

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. After this change cv2.resize() stopped working in my script and only outputs max resolution from my webcam. I also tried imutils library but without success.I tried using both:

  • 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

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:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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