gpt4 book ai didi

python - 如何在 Opencv Python 中缩放网络摄像头?

转载 作者:太空宇宙 更新时间:2023-11-04 09:43:17 25 4
gpt4 key购买 nike

我希望在 open cv python 中放大我的网络摄像头,但我不知道该怎么做。谁能帮我解决我的问题?

import cv2
video = cv2.VideoCapture(0)
while True:
check, frame = video.read()
cv2.imshow('Video', frame)
key = cv2.waitKey(1)
if key == 27:
break
video.release()
cv2.destroyAllWindows

最佳答案

您可以使用此解决方案。它使工作 -> 裁剪 + 缩放 + 向上排列和向下排列。

import cv2

def show_webcam(mirror=False):
scale=10

cam = cv2.VideoCapture(0)
while True:
ret_val, image = cam.read()
if mirror:
image = cv2.flip(image, 1)


#get the webcam size
height, width, channels = image.shape

#prepare the crop
centerX,centerY=int(height/2),int(width/2)
radiusX,radiusY= int(scale*height/100),int(scale*width/100)

minX,maxX=centerX-radiusX,centerX+radiusX
minY,maxY=centerY-radiusY,centerY+radiusY

cropped = image[minX:maxX, minY:maxY]
resized_cropped = cv2.resize(cropped, (width, height))

cv2.imshow('my webcam', resized_cropped)
if cv2.waitKey(1) == 27:
break # esc to quit

#add + or - 5 % to zoom

if cv2.waitKey(1) == 0:
scale += 5 # +5

if cv2.waitKey(1) == 1:
scale = 5 # +5

cv2.destroyAllWindows()


def main():
show_webcam(mirror=True)


if __name__ == '__main__':
main()

关于python - 如何在 Opencv Python 中缩放网络摄像头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50870405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com