123456789101112131415161718192021222324252627282930313233343536373839404142 |
- offline = False
- try:
- from luma.led_matrix.device import max7219
- from luma.core.interface.serial import spi, noop
- from luma.core.render import canvas
- except ModuleNotFoundError as e:
- offline = True
- import numpy as np
- from PIL import Image, ImageDraw
- import cv2
- cap = cv2.VideoCapture(-1)
- if not offline:
- # create matrix device
- serial = spi(port=0, device=0, gpio=noop())
- device = max7219(serial, cascaded=4, block_orientation=-90, rotate=0)
- print("Created device")
- while True:
- success, image = cap.read()
- if success:
- image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
- width, h = image.shape
- height = int(width/32*8)
- offset = int(h/2-height/2)
- image = image[offset:offset+height, :]
- image = cv2.resize(image, (32,8), interpolation = cv2.INTER_AREA)
- image = cv2.Canny(image, 0, 200)
- im = Image.fromarray(image)
- im = im.convert('1')
- if offline:
- image = np.asarray(im.convert("RGB"))
- cv2.imshow("image", cv2.resize(image, (640,120), interpolation = cv2.INTER_NEAREST))
- if cv2.waitKey(1) & 0xFF == ord('q'):
- break
- else:
- with canvas(device, im) as draw:
- pass
- else:
- exit(1)
|