Issues (3)

fullcyclepy/helpers/camerahelper.py (1 issue)

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