In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to apply face recognition SDK in webcams". 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!
1. Haikang SDK access basic process
a. Initialize and log in for authentication
NET_DVR_Init (); NET_DVR_DEVICEINFO_V30 struDeviceInfo = {0}; long lUserID = NET_DVR_Login_V30 (m_cameraIp, m_cameraPort, m_cameraUser, m_cameraPwd, & struDeviceInfo); if (lUserID
< 0) { NET_DVR_Cleanup(); return false; } b.创建线程并注册回调函数 thread videoThread(&HCNetCamera::getCameraPreview, this); videoThread.detach(); bool HCNetCamera::getCameraPreview() { NET_DVR_CLIENTINFO ClientInfo; ClientInfo.lChannel = 1; //Channel number 设备通道号 ClientInfo.hPlayWnd = NULL; //窗口为空,设备SDK不解码只取流 ClientInfo.lLinkMode = 0; //Main Stream ClientInfo.sMultiCastIP = NULL; //预览取流 g_realHandle = NET_DVR_RealPlay_V30(g_cameraUserId, &ClientInfo, fRealDataCallBack, NULL, TRUE); if (g_realHandle < 0) { qDebug() nType == T_YV12) { { lock_guard locker(g_CameraMutex); Utils_ns::ImageUtils_ns::YV12ToBGR24_FFMPEG((unsigned char*)pBuf, (unsigned char*)g_curRGBImage->ImageData, pFrameInfo- > nWidth, pFrameInfo- > nHeight); / / get all RGB images}
d. The application layer acquires video frames. In order to simplify the operation, only the current frame is obtained. You can also use thread-safe queues to deal with it.
Int HCNetCamera::getFrame (Mat& image) {lock_guard locker (g_CameraMutex); if (g_curRGBImage & & gcurcurRGBImage-> imageData) {image = gaccurate curRGBImage; return 0;} return-1 } / / the following is part of the threading function, mainly taking frames, and then performing face detection {lock_guard locker (g_CameraMutex); int ret = masking camera-> getFrame (curFrame); if (ret = =-1) {continue;}} ftProcessor- > faceDetect (curFrame); 2. Basic image format conversion
Currently, Rainbow soft SDK supports the following image data formats:
In the actual development process, generally use opencv,opencv default image data format is BGR24, and I use Haikang camera video coding format is H264, video frame data format is YV12, so I need to convert YV12 to BGR24, but also explain how to convert to other formats supported by Rainbow soft SDK, mainly refer to [2], the following code is for reference only.
A.YV12 To BGR24
Void yv12ToBGR24 (unsigned char* yv12, unsigned char* bgr24, int width, int height) {unsigned char* y_yv12 = yv12; unsigned char* v_yv12 = yv12 + width*height; unsigned char* u_yv12 = yv12 + width*height + width*height / 4; unsigned char* b = bgr24; unsigned char* g = bgr24 + 1; unsigned char* r = bgr24 + 2; int yIndex, uIndex, vIndex; for (int I = 0; I < height + + I) {for (int j = 0; j < width; + + j) {yIndex = I * width + j; vIndex = (I / 2) * (width / 2) + (j / 2); uIndex = vIndex; * b = (unsigned char) (yyv12 [yIndex] + 1.732446 * (uyv12 [vIndex]-128)) * g = (unsigned char) (yyv12 [yIndex]-0.698001 * (uyv128uIndex)-0.703125 * (vyv12 [vIndex]-128); * r = (unsigned char) (yyv12 [yIndex] + 1.370705 * (vyv12uIndex)); b + = 3; g + = 3; r + = 3 }}}
B.YV12 To I420
Void yv12ToI420 (unsigned char* yv12, unsigned char* i420, int width, int height) {unsigned char* y_yv12 = yv12; unsigned char* v_yv12 = yv12 + width*height; unsigned char* u_yv12 = yv12 + width*height + width*height / 4; unsigned char* y_i420 = i420; unsigned char* u_i420 = i420 + width*height; unsigned char* v_i420 = i420 + width*height + width*height / 4; memcpy (i420, yv12, width*height) Memcpy (v_i420, v_yv12, width*height / 4); memcpy (u_i420, u_yv12, width*height / 4);}
C.YV12 To NV21
Void yv12ToNV21 (unsigned char* yv12, unsigned char* nv21, int width, int height) {unsigned char* y_yv12 = yv12; unsigned char* v_yv12 = yv12 + width*height; unsigned char* u_yv12 = yv12 + width*height + width*height / 4; unsigned char* y_nv21 = nv21; unsigned char* v_nv21 = nv21 + width*height; unsigned char* u_nv21 = nv21 + width*height + 1; memcpy (nv21, yv12, width*height); for (int I = 0 I < width*height / 4; + + I) {* v_nv21 = * vSecretyv12; * u_nv21 = * upliyv12; v_nv21 + = 2; u_nv21 + = 2; + + vdeterminyv12; + + upliyv12;}}
D.YV12 To NV12
Void yv12ToNV12 (unsigned char* yv12, unsigned char* nv12, int width, int height) {unsigned char* y_yv12 = yv12; unsigned char* v_yv12 = yv12 + width*height; unsigned char* u_yv12 = yv12 + width*height + width*height / 4; unsigned char* y_nv12 = nv12; unsigned char* u_nv12 = nv12 + width*height; unsigned char* v_nv12 = nv12 + width*height + 1; memcpy (nv12, yv12, width*height); for (int I = 0 I < width*height / 4; + + I) {* v_nv12 = * vSecretyv12; * u_nv12 = * upliyv12; v_nv12 + = 2; u_nv12 + = 2; + + vdeterminyv12; + + upliyv12;}}
E.YV12 To YUYV
Void yv12ToYUYV (unsigned char* yv12, unsigned char* yuyv, int width, int height) {unsigned char* y_yv12 = yv12; unsigned char* v_yv12 = yv12 + width*height; unsigned char* u_yv12 = yv12 + width*height + width*height / 4; unsigned char* y_yuyv = yuyv; unsigned char* u_yuyv = yuyv + 1; unsigned char* v_yuyv = yuyv + 3; for (int I = 0; I < width + + I) {for (int j = 0; j < height; + + j) {* y_yuyv = * yroomyv12; y_yuyv + = 2; + + yambiyv12;}} for (int j = 0; j < height / 2; + + j) {for (int I = 0; I < width / 2) + + I) {* u_yuyv = * uroomyv12; * (u_yuyv + width * 2) = * upliyv12; u_yuyv + = 4; + + upliyv12; * v_yuyv = * vdeterminyv12; * (v_yuyv + width * 2) = * vSecretyv12; v_yuyv + = 4; + + v_yv12 } u_yuyv + = width * 2; v_yuyv + = width * 2;}} "how to use face recognition SDK in webcams" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.