Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the face recognition server with Qt

2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to achieve face recognition server with Qt". In daily operation, I believe many people have doubts about how to achieve face recognition server with Qt. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to achieve face recognition server with Qt". Next, please follow the editor to study!

I. Preface

The custom face recognition protocol uses the tcp communication protocol, in fact, it can also be changed to the http protocol, which is also the practice of most manufacturers. After all, http post is very popular now, it has good versatility, and the return of json data is very standardized. The tcp protocol currently used in this program is to be compatible with the old system. After all, the previous system is defined according to that format. The programs of many devices written before restarting need to be changed, so one must be too busy, and the previous programs have been tested by a large number of field applications and are very stable. once the program is changed, it will take a long time to run-in testing.

Custom face recognition protocol features:

Offline use, while supporting Baidu offline package and embedded linux face recognition static library.

Support multiple concurrent connections, automatic queuing processing, return with a unique identity to distinguish.

Input a single image to return to the face area.

Input a single picture to return facial eigenvalues.

Input a single picture or multiple pictures to return whether it is alive or not.

Pass in two pictures to return the comparison result.

Pass in two eigenvalues to return the alignment result.

Input a single picture to add a face.

Specifies a unique identifier to delete the face.

Input a single photo to return the face information with the greatest similarity.

Modify the configuration parameters of face service, such as whether to find quickly, the proportion of face, and so on.

II. Functional features

The supported functions include face recognition, face comparison, face search, live detection and so on.

The online version also supports ID card, driver's license, driving license, bank card and other identification.

The online version of the protocol supports Baidu, absenteeism, and the offline version supports Baidu, which can be customized.

In addition to supporting X86 architecture, it also supports embedded linux such as contex-A9, raspberry pie and so on.

The execution of each function returns not only the result but also the execution time.

Multithreading, which controls the current processing type through type.

Support a single image to retrieve the most similar images.

Support to specify directory images to generate facial feature value files.

You can set the number of pictures waiting to be processed in the queue.

A success or failure signal is returned for each execution.

The return results of face search include the original image + maximum similarity map + similarity and so on.

Face comparison supports two pictures and two eigenvalues at the same time.

Related functions customize a set of protocols for client and server, which can interact through TCP communication.

The custom face recognition protocol is very suitable for the scene where several devices are requested by a server in the center.

Each module is a separate class with neat code and perfect comments.

Third, effect picture

4. Core code void FaceSdkSocket::checkData () {QMutexLocker locker (& mutex); QDomDocument dom; if (! DeviceFun::getReceiveXmlData (buffer, dom, "IFACE:", 10)) {return;} / / take out the node one by one to judge the data emit receiveData (clientIP, dom.toString ()); QDomElement element = dom.documentElement () If (element.tagName () = = "FaceClient") {QString deviceIP = element.attribute ("DeviceIP"); QDomNode childNode = element.firstChild (); QString name = childNode.nodeName (); QString value = element.text (); / / qDebug () append (flag, image); # elif facearm FaceLocalArm::Instance ()-> setType (0); FaceLocalArm::Instance ()-> append (flag, image) # endif} else if (name = = "FindFeature") {element = childNode.toElement (); value = element.text (); if (value.length () = = 0) {return } / / combine the connection descriptor with the descriptor passed in by the user to facilitate the receiver to determine which connection QString faceID = element.attribute ("FaceID"); QString flag = QString ("% 1% 2") .Arg (this- > socketDescriptor ()) .arg (faceID); QImage image = DeviceFun::getImage (value); checkImage (image) Emit receiveAnaly (deviceIP, "request facial features"); / / send to the face recognition thread # ifdef facelocal FaceLocalBaiDu::Instance ()-> setType (1); FaceLocalBaiDu::Instance ()-> append (flag, image); # elif facearm FaceLocalArm::Instance ()-> setType (1); FaceLocalArm::Instance ()-> append (flag, image) # endif} else if (name = = "FindLive") {element = childNode.toElement (); value = element.text (); if (value.length () = = 0) {return } / / combine the connection descriptor with the descriptor passed in by the user to facilitate the receiver to determine which connection QString faceID = element.attribute ("FaceID"); QString flag = QString ("% 1% 2") .Arg (this- > socketDescriptor ()) .arg (faceID); QImage image = DeviceFun::getImage (value); checkImage (image) Emit receiveAnaly (deviceIP, "request live detection"); / / send to face recognition thread processing # ifdef facelocal FaceLocalBaiDu::Instance ()-> setType (5); FaceLocalBaiDu::Instance ()-> append (flag, image); # endif} else if (name = = "CompareByImage") {/ / take out child node QDomNodeList nodeList = childNode.childNodes () Int nodeCount = nodeList.count (); if (nodeCount = = 2) {QString faceID1, faceID2; QImage faceImage1, faceImage2; for (int I = 0; I

< nodeCount; i++) { childNode = nodeList.at(i); element = childNode.toElement(); name = childNode.nodeName(); value = element.text(); if (name == "FaceImage1") { faceID1 = element.attribute("FaceID"); faceImage1 = DeviceFun::getImage(value); } else if (name == "FaceImage2") { faceID2 = element.attribute("FaceID"); faceImage2 = DeviceFun::getImage(value); } } checkImage(faceImage1); checkImage(faceImage2); QString flag1 = QString("%1_%2").arg(this->

SocketDescriptor () .arg (faceID1); QString flag2 = QString ("% 1% 2") .arg (this- > socketDescriptor ()) .arg (faceID2); emit receiveAnaly (deviceIP, "request for face photo comparison"); / / send to the face recognition thread processing # ifdef facelocal FaceLocalBaiDu::Instance ()-> setType (2) FaceLocalBaiDu::Instance ()-> append (flag1 + "|" + flag2, faceImage1, faceImage2); # elif facearm FaceLocalArm::Instance ()-> setType (2); FaceLocalArm::Instance ()-> append (flag1 + "|" + flag2, faceImage1, faceImage2); # endif} else if (name = "CompareByFeature") {element = childNode.toElement () QString faceID = element.attribute ("FaceID"); / / take out child nodes QDomNodeList nodeList = childNode.childNodes (); int nodeCount = nodeList.count (); if (nodeCount = = 2) {QStringList faceFeature1, faceFeature2; for (int I = 0; I)

< nodeCount; i++) { childNode = nodeList.at(i); element = childNode.toElement(); name = childNode.nodeName(); value = element.text(); if (name == "FaceFeature1") { faceFeature1 = value.split("|"); } else if (name == "FaceFeature2") { faceFeature2 = value.split("|"); } } emit receiveAnaly(deviceIP, "请求人脸特征比对"); //特征比对速度非常快,忽略不计,立即比对并将结果返回 int count1 = faceFeature1.count(); int count2 = faceFeature2.count(); if (count1 != 256 || count2 != 256) { sendMsg("faceFeature count != 256"); return; } QList feature1, feature2; for (int i = 0; i < 256; i++) { feature1 getFaceCompare(faceID, feature1, feature2); sendFaceCompare(faceID, result, 1);#endif } } else if (name == "AppendFace") { element = childNode.toElement(); value = element.text(); if (value.length() == 0) { return; } //用连接的描述符加上用户传入的描述符组合,方便接收处判断发送给那个连接 QString faceID = element.attribute("FaceID"); QString flag = QString("%1_%2").arg(this->

SocketDescriptor () .arg (faceID); QImage image = DeviceFun::getImage (value); checkImage (image); emit receiveAnaly (deviceIP, "add face"); / / send to the face recognition thread processing QString file = QString ("% 1/%2.txt") .arg (FACEPATH) .arg (faceID) # ifdef facelocal FaceLocalBaiDu::Instance ()-> appendFace (flag, image, file); # elif facearm FaceLocalArm::Instance ()-> appendFace (flag, image, file); # endif} else if (name = = "DeleteFace") {element = childNode.toElement (); value = element.text (); if (value.length () = = 0) {return } / / combine the connected descriptors with the descriptors passed in by the user to facilitate the receiver to determine which connection QString faceID = element.attribute ("FaceID"); emit receiveAnaly (deviceIP, "delete face"); / / send it to the face recognition thread for processing # ifdef facelocal FaceLocalBaiDu::Instance ()-> deleteFace (faceID) # elif facearm FaceLocalArm::Instance ()-> deleteFace (faceID); # endif sendOk ();} else if (name = = "FindByImage") {element = childNode.toElement (); value = element.text (); if (value.length () = = 0) {return } / / combine the connection descriptor with the descriptor passed in by the user to facilitate the receiver to determine which connection QString faceID = element.attribute ("FaceID"); QString flag = QString ("% 1% 2") .Arg (this- > socketDescriptor ()) .arg (faceID); QImage image = DeviceFun::getImage (value); checkImage (image) Emit receiveAnaly (deviceIP, "find faces by picture"); / / send to the face recognition thread # ifdef facelocal FaceLocalBaiDu::Instance ()-> setOneImg (flag, image); # elif facearm FaceLocalArm::Instance ()-> setOneImg (flag, image); # endif} else if (name = = "FindByFeature") {element = childNode.toElement () Value = element.text (); if (value.length () = = 0) {return;} / / combines the descriptor of the connection with the descriptor passed in by the user to facilitate the receiver to determine which connection is sent to QString faceID = element.attribute ("FaceID"); QStringList faceFeature = value.split ("|") Emit receiveAnaly (deviceIP, "find faces by features"); int count = faceFeature.count (); if (count! = 256) {return;} QList feature; for (int I = 0; I

< 256; i++) { feature getFaceOne(faceID, feature, targetName, result, msec);#elif facearm FaceLocalArm::Instance()->

GetFaceOne (faceID, feature, targetName, result, msec); # endif if (! targetName.isEmpty ()) {QString imageFile = QString ("% 1Accord% 2") .arg (FACEPATH) .arg (targetName); sendFaceCompareOne (faceID, QImage (), QImage (imageFile), targetName, result, msec);} else if (name = "UpdateConfig") {element = childNode.toElement () Emit receiveAnaly (deviceIP, "modify face configuration"); bool findFast = (element.attribute ("FindFast") = = "true"? True: false); int facePercent = element.attribute ("FacePercent"). ToInt (); # ifdef facelocal FaceLocalBaiDu::Instance ()-> setFindFast (findFast); FaceLocalBaiDu::Instance ()-> setPercent (facePercent); # elif facearm FaceLocalArm::Instance ()-> setFindFast (findFast); FaceLocalArm::Instance ()-> setPercent (facePercent); # endif / / reply sendFaceConfig (findFast, facePercent) immediately Emit configChanged (findFast, facePercent);}} void FaceSdkSocket::checkImage (const QImage & image) {/ / if the photo width and height is too large, send a prompt to the client if (image.width () > = 1280 | | image.height () > = 720) {sendMsg ("Image Size Is Too Large");}} void FaceSdkSocket::setClientIP (const QString & clientIP) {this- > clientIP = clientIP } QString FaceSdkSocket::getClientIP () {return this- > clientIP;} void FaceSdkSocket::sendData (const QString & body) {/ / build xml string QStringList list; list.append (QString ("") .arg (clientIP) .arg (DATETIME)); list.append (body); list.append (""); QString data = DeviceFun::getSendXmlData (list.join (")," IFACE: "); this- > write (data.toUtf8 ()) Emit sendData (clientIP, data);} void FaceSdkSocket::sendOk () {sendData ("); emit sendAnaly (clientIP," heartbeat response ");} void FaceSdkSocket::sendMsg (const QString & msg) {sendData (QString ("% 1 ") .arg (msg)); emit sendAnaly (clientIP," prompt ") } void FaceSdkSocket::sendFaceRect (const QString & faceID, const QString & faceRect, int msec) {QString data = QString ("% 2") .arg (faceID) .arg (faceRect) .arg (msec); sendData (data); emit sendAnaly (clientIP, "return to face area") } void FaceSdkSocket::sendFaceFeature (const QString & faceID, const QString & faceFeature, int msec) {QString data = QString ("% 2") .arg (faceID) .arg (faceFeature) .arg (msec); sendData (data); emit sendAnaly (clientIP, "return facial features") } void FaceSdkSocket::sendFaceCompare (const QString & faceID, float result, int msec) {QString data = QString ("") .arg (faceID) .arg (result) .arg (msec); sendData (data); emit sendAnaly (clientIP, "return the result of face comparison") } void FaceSdkSocket::sendFaceCompareOne (const QString & faceID, const QImage & sourceImage, const QImage & targetImage, const QString & targetName, float result, int msec) {QString data = QString ("% 4 |% 5") .arg (faceID) .arg (result) .arg (DeviceFun::getImageData (sourceImage)) .arg (DeviceFun::getImageData (targetImage)) .arg (msec); sendData (data); emit sendAnaly (clientIP, "return the most similar face") At this point, the study of "how to implement the face recognition server with Qt" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report