// // Created by basic on 19-8-19. // #include "common.h" #include #include #include std::queue qImg2Extr; std::mutex mtxImg2Extract; std::queue qFeature2Comp; std::mutex mtxFeature2Comp; std::map mFaceRec; std::map mIDName; //std::mutex mtxFrameShow; //std::queue qFrameShow; void pushQImg2Extr(ImgToExtract *imgToExtract) { std::unique_lock lock(mtxImg2Extract, std::defer_lock); lock.lock(); if (qImg2Extr.size() > MAX_IMG2EXT) { auto imgFaces = qImg2Extr.front(); std::cout << "qImg2Extr.size() > MAX_IMG2EXT" << &(imgFaces->imgData)<< std::endl; delete imgFaces->imgData; for (auto face:imgFaces->vFaces) { delete face; } qImg2Extr.pop(); } std::cout << "qImg2Extr.push" << std::endl; qImg2Extr.push(imgToExtract); lock.unlock(); } //ImgToExtract *popQImg2Extr() { // std::unique_lock lock(mtxImg2Extract); // if (!qImg2Extr.empty()) { // ImgToExtract *imgFaces = qImg2Extr.front(); // qImg2Extr.pop(); // return imgFaces; // } // return nullptr; //} double msecond(void) { struct timeval tv; gettimeofday(&tv, 0); return (tv.tv_sec * 1.0e3 + tv.tv_usec * 1.0e-3); } static long int crv_tab[256]; static long int cbu_tab[256]; static long int cgu_tab[256]; static long int cgv_tab[256]; static long int tab_76309[256]; static unsigned char clp[1024]; //for clip in CCIR601 void init_yuv420p_table(void) { long int crv, cbu, cgu, cgv; int i, ind; crv = 104597; cbu = 132201; /* fra matrise i global.h */ cgu = 25675; cgv = 53279; for (i = 0; i < 256; i++) { crv_tab[i] = (i - 128) * crv; cbu_tab[i] = (i - 128) * cbu; cgu_tab[i] = (i - 128) * cgu; cgv_tab[i] = (i - 128) * cgv; tab_76309[i] = 76309 * (i - 16); } for (i = 0; i < 384; i++) clp[i] = 0; ind = 384; for (i = 0; i < 256; i++) clp[ind++] = i; ind = 640; for (i = 0; i < 384; i++) clp[ind++] = 255; } /** 内存分布 w +--------------------+ |Y0Y1Y2Y3... | |... | h |... | | | +--------------------+ |U0U1 | |... | h/2 |... | | | +----------+ |V0V1 | |... | h/2 |... | | | +----------+ w/2 */ void yuv420p_to_rgb24_c(unsigned char *yuvbuffer, unsigned char *rgbbuffer, int width, int height) { int y1, y2, u, v; unsigned char *py1, *py2; int i, j, c1, c2, c3, c4; unsigned char *d1, *d2; unsigned char *src_u, *src_v; static int init_yuv420p = 0; src_u = yuvbuffer + width * height; // u src_v = src_u + width * height / 4; // v py1 = yuvbuffer; // y py2 = py1 + width; d1 = rgbbuffer; d2 = d1 + 3 * width; if (init_yuv420p == 0) { init_yuv420p_table(); init_yuv420p = 1; } for (j = 0; j < height; j += 2) { for (i = 0; i < width; i += 2) { u = *src_u++; v = *src_v++; c1 = crv_tab[v]; c2 = cgu_tab[u]; c3 = cgv_tab[v]; c4 = cbu_tab[u]; //up-left y1 = tab_76309[*py1++]; *d1++ = clp[384 + ((y1 + c4) >> 16)]; *d1++ = clp[384 + ((y1 - c2 - c3) >> 16)]; *d1++ = clp[384 + ((y1 + c1) >> 16)]; //down-left y2 = tab_76309[*py2++]; *d2++ = clp[384 + ((y2 + c4) >> 16)]; *d2++ = clp[384 + ((y2 - c2 - c3) >> 16)]; *d2++ = clp[384 + ((y2 + c1) >> 16)]; //up-right y1 = tab_76309[*py1++]; *d1++ = clp[384 + ((y1 + c4) >> 16)]; *d1++ = clp[384 + ((y1 - c2 - c3) >> 16)]; *d1++ = clp[384 + ((y1 + c1) >> 16)]; //down-right y2 = tab_76309[*py2++]; *d2++ = clp[384 + ((y2 + c4) >> 16)]; *d2++ = clp[384 + ((y2 - c2 - c3) >> 16)]; *d2++ = clp[384 + ((y2 + c1) >> 16)]; } d1 += 3 * width; d2 += 3 * width; py1 += width; py2 += width; } }