diff --git a/requirements.txt b/requirements.txt index 8fa58fd9..c0e63faf 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,12 +1,11 @@ embit==0.4.10 numpy==1.21.1 # need to not install this on x86... -#picamera==1.13 +picamera==1.13 Pillow==8.2.0 -e git+https://github.com/kdmukai/pyzbar.git@c3c237821c6a20b17953efe59b90df0b514a1c03#egg=pyzbar qrcode==7.3.1 -#RPi.GPIO==0.7.1 +RPi.GPIO==0.7.1 six==1.16.0 spidev==3.5 urtypes @ git+https://github.com/jreesun/urtypes.git@e0d0db277ec2339650343eaf7b220fffb9233241 -#-e src/vendor/urtypes diff --git a/src/seedsigner/camera.py b/src/seedsigner/camera.py index edac1702..82780bdc 100644 --- a/src/seedsigner/camera.py +++ b/src/seedsigner/camera.py @@ -49,32 +49,36 @@ class Camera(Singleton): def start_single_frame_mode(self, resolution=(720, 480)): - if self._video_stream is not None: - self.stop_video_stream_mode() - if self._picamera is not None: - self._picamera.close() + pass + # self._video_stream.should_stop = True + # if self._video_stream is not None: + # self.stop_video_stream_mode() + # if self._picamera is not None: + # self._picamera.close() - self._picamera = PiCamera(resolution=resolution, framerate=24) - self._picamera.start_preview() + # self._picamera = PiCamera(resolution=resolution, framerate=24) + # self._picamera.start_preview() def capture_frame(self): - if self._picamera is None: - raise Exception("Must call start_single_frame_mode first.") + # if self._picamera is None: + # raise Exception("Must call start_single_frame_mode first.") # Set auto-exposure values - self._picamera.shutter_speed = self._picamera.exposure_speed - self._picamera.exposure_mode = 'off' - g = self._picamera.awb_gains - self._picamera.awb_mode = 'off' - self._picamera.awb_gains = g + # self._picamera.shutter_speed = self._picamera.exposure_speed + # self._picamera.exposure_mode = 'off' + # g = self._picamera.awb_gains + # self._picamera.awb_mode = 'off' + # self._picamera.awb_gains = g stream = io.BytesIO() - self._picamera.capture(stream, format='jpeg') + self._video_stream + # self._picamera.capture(stream, format='jpeg') # "Rewind" the stream to the beginning so we can read its content - stream.seek(0) - return Image.open(stream).rotate(90 + self._camera_rotation) + # stream.seek(0) + # return Image.open(stream) + return Image.fromarray(self._video_stream.frame.astype('uint8'), 'RGB').rotate(90) def stop_single_frame_mode(self): diff --git a/src/seedsigner/controller.py b/src/seedsigner/controller.py index a41f7d0b..dc21082c 100644 --- a/src/seedsigner/controller.py +++ b/src/seedsigner/controller.py @@ -5,6 +5,7 @@ from multiprocessing import Process, Queue from subprocess import call import os, sys from embit import bip32, script, ec +import traceback from embit.networks import NETWORKS from embit.descriptor import Descriptor from binascii import hexlify @@ -135,6 +136,7 @@ class Controller(Singleton): break else: print('Caught this error: ' + repr(error)) # debug + print(traceback.format_exc()) self.menu_view.draw_modal(["Crashed ..."], "", "restarting") time.sleep(5) diff --git a/src/seedsigner/helpers/pivideostream.py b/src/seedsigner/helpers/pivideostream.py index 486dc848..7afa5332 100644 --- a/src/seedsigner/helpers/pivideostream.py +++ b/src/seedsigner/helpers/pivideostream.py @@ -5,18 +5,26 @@ if not os.getenv("NOTAPI", False): from picamera import PiCamera from threading import Thread import time - +import cv2 +import numpy as np # Modified from: https://github.com/jrosebr1/imutils class PiVideoStream: def __init__(self, resolution=(320, 240), framerate=32, format="bgr", **kwargs): # initialize the camera - self.camera = PiCamera(resolution=resolution, framerate=framerate, **kwargs) + # self.camera = PiCamera(resolution=resolution, framerate=framerate, **kwargs) # initialize the stream - self.rawCapture = PiRGBArray(self.camera, size=resolution) - self.stream = self.camera.capture_continuous(self.rawCapture, - format=format, use_video_port=True) + # self.rawCapture = PiRGBArray(self.camera, size=resolution) + # self.stream = self.camera.capture_continuous(self.rawCapture, + # format=format, use_video_port=True) + + self.cap = cv2.VideoCapture(0) + self.cap.set(3, 320) + self.cap.set(4, 240) + + # img1 = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) + # initialize the frame and the variable used to indicate # if the thread should be stopped @@ -34,23 +42,32 @@ class PiVideoStream: def update(self): # keep looping infinitely until the thread is stopped - for f in self.stream: + # for f in self.stream: + while True: + ret, frame = self.cap.read() + self.frame = frame # grab the frame from the stream and clear the stream in # preparation for the next frame - self.frame = f.array - self.rawCapture.truncate(0) + # self.frame = f.array + # self.rawCapture.truncate(0) # if the thread indicator variable is set, stop the thread # and resource camera resources if self.should_stop: print("PiVideoStream: closing everything") - self.stream.close() - self.rawCapture.close() - self.camera.close() + # self.stream.close() + # self.rawCapture.close() + # self.camera.close() + self.cap.release() self.should_stop = False self.is_stopped = True return + def get_frame(self): + ret, frame = self.cap.read() + self.frame = frame + return frame + def read(self): # return the frame most recently read return self.frame