|
@@ -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()
|
|
|
|
|
+
|