-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale_camera.py
47 lines (33 loc) · 1.09 KB
/
scale_camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 20 14:39:32 2021
@author: gat06
"""
import cv2
def show_webcam():
scale=20
cam = cv2.VideoCapture(0)
while True:
ret_val, image = cam.read()
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) & 0xFF == ord('q'):
break # esc to quit
if cv2.waitKey(1) & 0xFF == ord('w'):
scale =scale + 5 # +5
if cv2.waitKey(1) & 0xFF == ord('s'):
scale =scale - 5 # +5
cv2.destroyAllWindows()
def main():
show_webcam()
if __name__ == '__main__':
main()