Преглед на файлове

wip

* motion.conf for motion serving video feed through loopback /dev/video1
* python opencv camera capture and qr/barcode reading
* manager to pump video from python opencv from /dev/video0 to /dev/video1
abe преди 5 години
родител
ревизия
67844f90a8
променени са 3 файла, в които са добавени 148 реда и са изтрити 0 реда
  1. 28 0
      busunit-PIU/rootfs/home/bus/.motion/motion.conf
  2. 87 0
      busunit-PIU/scripts/qr_cam_filter
  3. 33 0
      busunit-PIU/scripts/qr_manager

+ 28 - 0
busunit-PIU/rootfs/home/bus/.motion/motion.conf

@@ -0,0 +1,28 @@
+stream_port 8080
+stream_quality 98
+stream_maxrate 25
+framerate 10
+
+stream_localhost on
+#stream_localhost off
+
+#picture_output on
+picture_output off
+
+output_pictures off
+
+framerate 30
+
+movie_output off
+#movie_filename /home/pi/log/movie.mp4
+#movie_code mkv
+#ffmpeg_video_code mpeg4
+
+width 320
+height 240
+auto_brightness off
+contrast 0
+saturation 0
+text_right ''
+videodevice /dev/video1
+log_file /home/pi/log/motion.log

+ 87 - 0
busunit-PIU/scripts/qr_cam_filter

@@ -0,0 +1,87 @@
+#!/usr/bin/python
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+#
+# This file is part of PopuFare.
+#
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+import sys
+import cv2
+import numpy as np
+
+from imutils.video import VideoStream
+from pyzbar import pyzbar
+import datetime
+import imutils
+import time
+
+out_type = "stdout"
+#out_type = "x11"
+
+#barcode_ofp = sys.stdout
+barcode_ofp = open("/tmp/qrcode.log", "a")
+
+cap = cv2.VideoCapture(0)
+
+# depending on which version of OpenCV is installed, different
+# constant namess might need to be used
+#
+#cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 320)
+#cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 240)
+cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
+cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
+
+while True:
+  ret, frame = cap.read()
+
+  #frame = cv2.flip(frame,1)
+  #added_image = cv2.addWeighted(frame[100:200,100:200,:],alpha,foreground[0:100,0:100,:],1-alpha,0)
+  #frame[100:200,100:200] = added_image
+  #font = cv2.FONT_HERSHEY_SIMPLEX
+
+  barcodes = pyzbar.decode(frame)
+  for barcode in barcodes:
+    (x,y,w,h) = barcode.rect
+    cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 0, 255), 2)
+
+    barcode_data = barcode.data.decode("utf-8")
+    barcode_type = barcode.type
+
+    show_text = "{} ({})".format(barcode_data, barcode_type)
+
+    cv2.putText(frame, show_text, (x, y - 10),
+      cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
+
+    barcode_ofp.write( str(datetime.datetime.now()) + ": " + barcode_data + "\n")
+    barcode_ofp.flush()
+
+  # see abov about constant names
+  #
+  #cv2.putText(frame,'alpha:{}'.format(alpha),(10,30), font, 1,(255,255,255),2,cv2.CV_AA)
+  #cv2.putText(frame,'alpha:{}'.format(alpha),(10,30), font, 1,(255,255,255),2,cv2.LINE_AA)
+
+  if out_type == "stdout":
+    sys.stdout.write( frame.tostring() )
+  elif out_type == "x11":
+    cv2.imshow("qr_cam_filter", frame)
+    key = cv2.waitKey(1) & 0xff
+    if key == ord('q'):
+      break
+
+barcode_ofp.close()
+cap.release()
+cv2.destroyAllWindows()
+

+ 33 - 0
busunit-PIU/scripts/qr_manager

@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+# Copyright (c) 2019 Clementine Computing LLC.
+#
+# This file is part of PopuFare.
+#
+# PopuFare is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PopuFare is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with PopuFare.  If not, see <https://www.gnu.org/licenses/>.
+#
+
+BASEDIR=/home/pi
+d=$BASEDIR/bin
+
+# setup /dev/video1
+#
+modprobe v4l2loopback
+
+# qr_cam filter outputs read qr codes to /tmp/qrcodes.log
+#
+$d/qr_cam_filter | \
+  ffmpeg -hide_banner -loglevel warning -nostats -f rawvideo -pixel_format bgr24 -video_size 320x240 -i - -f avi -speed 10 -q 3 -r 11  -fflags nobuffer - | \
+  ffmpeg -hide_banner -loglevel warning -nostats -f avi -i - -f v4l2 /dev/video1
+