[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: How to automatically processed frame from QCamera
From: Zdenko Podobny <zdenop () gmail ! com>
Date: 2021-11-19 20:18:10
Message-ID: CAJbzG8zxKRnw+VwGGcHvBSRzQ9aAXSui7w3qjDx7R=f1z=v+kg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
Hello,
with help from Tomas Sobota I have created the attached "prototype" for
real-time processing (bar code extraction) of the camera in pyqt
5.15.4.2.2.
BR,
Zdenko
po 15. 11. 2021 o 9:55 Zdenko Podobny <zdenop@gmail.com> napísal(a):
> Hello,
>
> I am trying to make a PyQt5 application for extracting QR codes from
> QCamera. Prototype is almost ready (see attachment), but I am not able to
> automatically process video frames – I need to click on the button...
>
> All examples for tasks like this, use opencv, but I do not want to use
> opencv for this (it took 30 seconds for opencv to start my camera and its
> barcode recognition is worse than pyzbar.)
>
> Any suggestions on how to automatically send frames to pyzbar (or any
> other post processing function)?
>
>
> BR,
>
>
> Zdenko
>
[Attachment #5 (text/html)]
<div dir="ltr"><div>Hello,</div><div><br></div>with help from Tomas Sobota I have \
created the attached "prototype" for real-time processing (bar code \
extraction) of the camera in pyqt 5.15.4.2.2. <div><br></div><div>BR,<br><div><br \
clear="all"><div><div dir="ltr" class="gmail_signature" \
data-smartmail="gmail_signature">Zdenko</div></div><br></div></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">po 15. 11. 2021 o 9:55 Zdenko \
Podobny <<a href="mailto:zdenop@gmail.com">zdenop@gmail.com</a>> \
napísal(a):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><p \
class="MsoNormal" style="margin:0cm 0cm \
10pt;line-height:115%;font-size:11pt;font-family:Calibri,"sans-serif""><span \
lang="EN-GB">Hello,</span></p>
<p class="MsoNormal" style="margin:0cm 0cm \
10pt;line-height:115%;font-size:11pt;font-family:Calibri,"sans-serif""><span \
lang="EN-GB">I am trying to make a PyQt5 application for extracting QR codes from \
QCamera. Prototype is almost ready (see attachment), but I am not able to \
automatically process video frames – I need to click on the button...</span></p>
<p class="MsoNormal" style="margin:0cm 0cm \
10pt;line-height:115%;font-size:11pt;font-family:Calibri,"sans-serif""><span \
lang="EN-GB">All examples for tasks like this, use opencv, but I do not want to use \
opencv for this (it took 30 seconds for opencv to
start my camera and its barcode recognition is worse than pyzbar.)</span></p>
<p class="MsoNormal" style="margin:0cm 0cm \
10pt;line-height:115%;font-size:11pt;font-family:Calibri,"sans-serif""><span \
lang="EN-GB">Any suggestions on how to automatically send frames to pyzbar (or any \
other post processing function)?</span></p><p class="MsoNormal" style="margin:0cm 0cm \
10pt;line-height:115%;font-size:11pt;font-family:Calibri,"sans-serif""><span \
lang="EN-GB"><br></span></p><p class="MsoNormal" style="margin:0cm 0cm \
10pt;line-height:115%;font-size:11pt;font-family:Calibri,"sans-serif""><span \
lang="EN-GB">BR,</span></p><p class="MsoNormal" style="margin:0cm 0cm \
10pt;line-height:115%;font-size:11pt;font-family:Calibri,"sans-serif""><span \
lang="EN-GB"><br></span></p><div><div dir="ltr">Zdenko</div></div></div> \
</blockquote></div>
["process_camera.py" (text/x-python)]
#!/usr/bin/env python
import io
import sys
import beepy
from PIL import Image
from PyQt5 import QtCore, QtMultimedia, QtGui
from PyQt5.QtMultimedia import *
from PyQt5.QtMultimediaWidgets import *
from PyQt5.QtWidgets import *
from pyzbar import pyzbar
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.available_cameras = QCameraInfo.availableCameras()
if not self.available_cameras:
print("No camera found.")
sys.exit()
self.known_codes = set()
self.camera = QCamera(self.available_cameras[0])
self.camera.setCaptureMode(QCamera.CaptureViewfinder)
self.camera.imageProcessing().setWhiteBalanceMode(QCameraImageProcessing.WhiteBalanceAuto)
self.current_camera_name = self.available_cameras[0].description()
self.capture = QCameraImageCapture(self.camera)
self.capture.setCaptureDestination(QCameraImageCapture.CaptureToBuffer)
self.probe = QtMultimedia.QVideoProbe(self)
self.probe.videoFrameProbed.connect(self.processFrame)
self.probe.setSource(self.camera)
exposure = self.camera.exposure()
exposure.setExposureMode(QCameraExposure.ExposureAuto)
exposure.setExposureCompensation(0)
exposure.setMeteringMode(QCameraExposure.MeteringSpot)
self.status = QStatusBar()
self.setStatusBar(self.status)
self.status.showMessage(f"Using {self.current_camera_name}")
self.viewfinder = QCameraViewfinder()
self.viewfinder.show()
self.setCentralWidget(self.viewfinder)
self.camera.setViewfinder(self.viewfinder)
toolbar = QToolBar()
self.addToolBar(toolbar)
start_action = QAction(
self.style().standardIcon(QStyle.SP_MediaPlay), "Start camera", self
)
start_action.triggered.connect(self.startCamera)
toolbar.addAction(start_action)
stop_action = QAction(
self.style().standardIcon(QStyle.SP_MediaStop), "Stop camera", self
)
stop_action.triggered.connect(self.stopCamera)
toolbar.addAction(stop_action)
self.setGeometry(100, 100, 800, 600)
self.show()
def startCamera(self):
self.camera.start()
def stopCamera(self):
self.camera.stop()
def processFrame(self, frame):
QApplication.processEvents()
if frame.isValid():
cloneFrame = QVideoFrame(frame)
cloneFrame.map(QAbstractVideoBuffer.MapMode.ReadOnly)
buffer = QtCore.QBuffer()
buffer.open(QtCore.QBuffer.ReadWrite)
frame.image().save(buffer, "JPEG")
pil_im = Image.open(io.BytesIO(buffer.data()))
barcodes = pyzbar.decode(pil_im)
for barcode in barcodes:
data = barcode.data.decode("utf-8")
if data not in self.known_codes:
self.known_codes.add(data)
message = f"Found Type : {barcode.type} Barcode : {data}"
self.status.showMessage(message)
print(message)
beepy.beep()
cloneFrame.unmap()
def closeEvent(self, event):
if self.probe.isActive():
self.probe.videoFrameProbed.disconnect(self.processFrame)
self.probe.deleteLater()
self.camera.stop()
event.accept()
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create("fusion"))
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic