s1 = image.shape # Image is an opencv2 image (ndarray)
w,h,d = s1
image_ = cv2.resize(image, (w*2, h*2), interpolation = cv2.INTER_CUBIC)
s2 = image_.shape
在上述代码中,我请求输出的大小为(960,1280),但实际得到的是(1280,960)。这是怎么回事呢?
image_ = cv2.resize(image, None, fx=2, fy=2, interpolation = cv2.INTER_CUBIC)
...正常工作(不需要指出这一点)。
可运行的示例:
import cv2
def run():
cap = cv2.VideoCapture(0)
while cap.isOpened():
success, image = cap.read() # (480, 640, 3)
if not success:
print("Ignoring empty camera frame.")
continue
s1 = image.shape
w, h, d = s1
s2 = (w * 2, h * 2)
image_ = cv2.resize(image, s2, interpolation=cv2.INTER_CUBIC)
s3 = image_.shape
cv2.imshow('Camera',
image_
)
key = cv2.waitKey(5)
if key & 0xFF == 27:
break
cap.release()
if __name__ == '__main__':
run()