Esempio n. 1
0
    def detect(self):
        _, img = self.cap.read()
        img = cv2.resize(img, (self.width, self.height))
        frame = np.zeros((self.detection_frame, self.detection_frame))

        img_thresh = self.apply_threshold(img)
        contours = cf.find_contours(img_thresh, square=True)

        for cnt, pts in contours:
            pts = mf.arrange_points(pts)
            frame = cf.warp_image(img_thresh, pts, frame)
            frame_inv = cf.invert(frame)
            frame_inv = cf.crop_square(frame_inv, 20)

            shapes = len(cf.find_contours(frame_inv, 0, 0))
            place = ""
            if shapes == 2:
                place = "Pasillo"
            elif shapes == 3:
                place = "Sala"
            else:
                place = "Cocina"
            printer.print_poly(img, pts, thickness=8)
            printer.print_text(img, pts[0][0] - 40, 40,
                               ("Frame detected", (255, 0, 0), 3),
                               (f"{shapes} detected", (0, 255, 0), 3),
                               (f"{place}", (0, 0, 255), 3))

        cv2.imshow("a", frame)
        cv2.imshow("b", img)
        cv2.imshow("c", img_thresh)
Esempio n. 2
0
import socket
import fcntl
import struct

from util import printer


def get_ip_address(ifname):
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack("256s", ifname[:15]))[20:24])  # SIOCGIFADDR


printer = printer.ThermalPrinter()
printer.print_text("Good Day!")
printer.linefeed()
printer.print_text("My ip address is:")
printer.linefeed()
printer.print_text(get_ip_address("eth0"))
printer.linefeed(3)
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

from util import printer

GPIO.setmode(GPIO.BCM)
GPIO.setup(11, GPIO.IN)

#initialise a previous input variable to 0 (assume button not pressed last)
prev_input = True
printer = printer.ThermalPrinter()

while True:
    input = GPIO.input(11) #take a reading
  #if the last reading was low and this one high, print
    if ((not prev_input) and input):
        printer.print_text("Button pressed!")
        printer.linefeed(3)
    prev_input = input #update previous input
    time.sleep(0.1) #slight pause to debounce
from util import printer

printer = printer.ThermalPrinter()

printer.print_text("Hello!")
printer.linefeed(3)