In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what is the implementation method of USB camera linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I. Preface
I have been developing on embedded linux for many years, and for at least 9 years, I have done many programs one after another, such as reading external USB camera or CMOS camera, capturing video in real time, transmitting the image to the front end, or analyzing and processing the image with human face. at the beginning, I tried QCamera to deal with it, and gave up directly. Later, I found that I wanted to use v4l2 video framework through search. So it has been tried many times, and it has been perfected for several years. No matter what program is written, it is found that it is very fast and easy to simply realize the basic functions, but if you want to do it well, you need to spend a lot of energy and time to improve it and adapt to different scenarios. For example, to load the camera with v4l2, you need to specify the device file to read. It is impossible for the user to assign to you at the scene, and frequent plugging will also lead to changes in the device file name, so you must find a mechanism to automatically find the device file name of the camera you want, such as turning on a timer to call the linux command to deal with, and even the commands to be executed on different system platforms are slightly different, if there are multiple local cameras that still need to distinguish between left and right and so on. Then it can only be distinguished by the order in which the power is turned on.
Linux scenario processing flow:
Call the encapsulated function findCamera to find the file name of the camera device in real time.
Call:: open function to open the device file.
Call the encapsulated function initCamera to initialize the camera parameters (image format, resolution, etc.).
Call:: select function to fetch a buffered frame from the buffer.
The buffered frame data is in yuyv format and needs to be converted from rgb24 to QImage.
Get the picture for drawing, face analysis, etc.
Close the device file.
II. Functional features
At the same time, it supports real-time acquisition of USB camera on windows, linux and embedded linux.
Support multi-channel USB camera multi-thread real-time acquisition.
On embedded linux devices, automatically find USB device files and load them.
The device file name can be set manually and loaded according to the device file set manually.
The face recognition interface is supported on the embedded linux device to draw the human face frame in real time.
With open, pause, resume, close, screenshot and other general functions.
Two OSD tags can be set, such as text, color, font size, position, etc.
It can be used as a video surveillance system.
Third, effect picture
4. The core code void CameraLinux::run () {while (! stopped) {if (! cameraOk) {msleep (10); continue;} if (isPause) {/ / needs to be assumed to be normal, and the time to continue updating during the pause period lastTime = QDateTime::currentDateTime (); msleep (10); continue } QImage image = readImage (); if (! image.isNull ()) {if (isSnap) {emit snapImage (image); isSnap = false;} if (findFaceOne) {findFace (image) } if (findFaceRect) {image = drawFace (image);} lastTime = QDateTime::currentDateTime (); emit receiveImage (image);} msleep (interval);} this- > closeCamera (); this- > initData ();} QDateTime CameraLinux::getLastTime () const {return this- > lastTime } QString CameraLinux::getCameraName () const {return this- > cameraName;} int CameraLinux::getCameraWidth () const {return this- > cameraWidth;} int CameraLinux::getCameraHeight () const {return this- > cameraHeight;} void CameraLinux::sleep (int msec) {if (msec > 0) {QTime endTime = QTime::currentTime (). AddMSecs (msec); while (QTime::currentTime ()
< endTime) { QCoreApplication::processEvents(QEventLoop::AllEvents, 100); } }}void CameraLinux::initData(){ stopped = false; isPause = false; isSnap = false; cameraOk = false; cameraHwnd = -1; errorCount = 0;}void CameraLinux::readData(){ QStringList cameraNames; while (!process->AtEnd () {/ / the result returned by line-by-line reading filter video begins with the camera device file QString line = process- > readLine (); if (line.startsWith ("video")) {line = line.replace ("\ n", "); cameraNames 0) {cameraName = cameraNames.first (); emit receiveCamera (cameraNames) QDebug () start ("ls / dev/");}} bool CameraLinux::openCamera () {# ifdef Q_OS_LINUX if (cameraName.length () > 5) {cameraHwnd =:: open (cameraName.toUtf8 (). Data (), O_RDWR | O_NONBLOCK, 0);} if (cameraHwnd < 0) {qDebug ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.