helpers.camerahelper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 7

1 Function

Rating   Name   Duplication   Size   Complexity  
B take_picture() 0 32 7
1
'''camera functions'''
2
import time
3
#import datetime
4
try:
5
    import picamera
6
except BaseException:
7
    try:
8
        import cv2
9
    except BaseException:
10
        pass
11
12
def take_picture(image_name, size="small", quality=10, brightness=50, contrast=50):
13
    try:
14
        with picamera.PiCamera() as camera:
15
            camera.start_preview()
16
            try:
17
                camera.resolution = (1280, 1024)
18
                camera.brightness = brightness
19
                camera.contrast = contrast
20
                #camera.anotate_text = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
21
                # Camera warm-up time
22
                time.sleep(2)
23
                resize = (320, 240)
24
                if size.startswith('m'):
25
                    resize = (640, 480)
26
                if size.startswith('l'):
27
                    resize = (1024, 768)
28
                if size.startswith('x'):
29
                    resize = (1280, 1024)
30
31
                camera.capture(image_name, resize=resize, quality=quality)
32
            finally:
33
                camera.stop_preview()
34
        return image_name
35
    except BaseException:
36
        #the problem with cv2 is that is appears to not work on rpi with python3
37
        camera = cv2.VideoCapture(0)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable cv2 does not seem to be defined.
Loading history...
38
        for _ in range(30):
39
            camera.read()
40
        _, frame = camera.read()
41
        cv2.imwrite(image_name, frame)
42
        camera.release()
43
        return image_name
44