| | |
| | | #include "PbFaceList.pb.h"
|
| | |
|
| | | #include <libyuv.h>
|
| | | #define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a))
|
| | |
|
| | | //#define YUV420_TO_RGB888 1
|
| | | #define YUV420_TO_RGB565 1
|
| | |
|
| | | struct FcPmBreackerContext
|
| | | {
|
| | |
| | | faceFeatures.clear();
|
| | | }
|
| | |
|
| | | bool convertYUV420ToRGB()
|
| | | bool convertYUV420ToRGB888()
|
| | | {
|
| | | #define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a))
|
| | |
|
| | | int src_height = height;
|
| | | int src_width = width;
|
| | | const uint8* src_y = (const uint8*)(frameYUV);
|
| | |
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | | bool convertYUV420ToRGB565()
|
| | | {
|
| | | int src_height = height;
|
| | | int src_width = width;
|
| | | const uint8* src_y = (const uint8*)(frameYUV);
|
| | | const uint8* src_u = (const uint8*)(src_y + (src_height * src_width));
|
| | | const uint8* src_v = (const uint8*)(src_u + (src_height * src_width / 4));
|
| | |
|
| | | libyuv::I420ToRGB565(src_y, src_width,
|
| | | src_u, SUBSAMPLE(src_width, 2),
|
| | | src_v, SUBSAMPLE(src_width, 2),
|
| | | frameRGB, 2 * src_width,
|
| | | src_width, src_height);
|
| | | frameRGBSize = src_height * src_width * 2;
|
| | | return true;
|
| | | }
|
| | | };
|
| | |
|
| | | bool fc_pm_breaker_ptr(const PipeMaterial* pm, void* args)
|
| | |
| | |
|
| | | ctx->dataAvailable &= true;
|
| | | return true;
|
| | | }
|
| | |
|
| | | NativeImgIdx::operator std::string() const
|
| | | {
|
| | | char buf[256];
|
| | | sprintf(buf, "offset=%d, size=%d, type=%d, width=%d, height=%d", offset, size, type, width, height);
|
| | | return std::string(buf);
|
| | | }
|
| | |
|
| | | #ifdef USE_ST_SDK
|
| | |
| | | for (int i = 0; i < ctx.faceFeatures.size(); i++)
|
| | | {
|
| | | const FaceRect& faceRect(ctx.faceFeatures[i].rect);
|
| | | cv::Mat roiMat(yMat, cv::Rect(faceRect.leftTop.x, faceRect.leftTop.y, faceRect.rightBottom.x - faceRect.leftTop.x, faceRect.rightBottom.y - faceRect.leftTop.y));
|
| | | size_t s = roiMat.total() * roiMat.elemSize();
|
| | | cv::Mat roiMat1(yMat, cv::Rect(faceRect.leftTop.x, faceRect.leftTop.y, faceRect.rightBottom.x - faceRect.leftTop.x, faceRect.rightBottom.y - faceRect.leftTop.y));
|
| | | cv::Mat roiMat(roiMat1.clone()); // #todo copy data should be avoid!!!!
|
| | | size_t s = roiMat.total() * roiMat.elemSize();
|
| | |
|
| | | PbFaceList_FaceListImage pbFaceListImage;
|
| | | pbFaceListImage.set_idx(i);
|
| | |
| | | return buffMaxSize > 0;
|
| | | }
|
| | |
|
| | | #ifdef YUV420_TO_RGB888
|
| | |
|
| | | bool FaceCache::getFaceListImage(std::vector<NativeImgIdx>& imgIdxes, uint8_t* buffImg, size_t& buffImgMaxSize)
|
| | | {
|
| | | FcPmBreackerContext& ctx(*(FcPmBreackerContext*)_ctx);
|
| | |
| | | if (ctx.frameRGBSize == 0)
|
| | | {
|
| | | //#todo should optimize not convert the whole image
|
| | | if (! ctx.convertYUV420ToRGB())
|
| | | if (! ctx.convertYUV420ToRGB888())
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | NativeImgIdx imgidx;
|
| | | imgidx.offset = offset;
|
| | | imgidx.size = roiMat.total() * roiMat.elemSize();
|
| | | imgidx.type = MB_Frame::MBFT_RGB;
|
| | | imgidx.type = MB_Frame::MBFT_RGB888;
|
| | | imgidx.width = roiMat.cols;
|
| | | imgidx.height = roiMat.rows;
|
| | |
|
| | |
| | | offset = newSize;
|
| | | }
|
| | |
|
| | | buffImgMaxSize = offset;
|
| | | return true;
|
| | | }
|
| | |
|
| | | #elif YUV420_TO_RGB565
|
| | |
|
| | | bool FaceCache::getFaceListImage(std::vector<NativeImgIdx>& imgIdxes, uint8_t* buffImg, size_t& buffImgMaxSize)
|
| | | {
|
| | | FcPmBreackerContext& ctx(*(FcPmBreackerContext*)_ctx);
|
| | | if (!ctx.dataAvailable)
|
| | | return false;
|
| | |
|
| | | if (ctx.frameRGBSize == 0)
|
| | | {
|
| | | //#todo should optimize not convert the whole image
|
| | | if (! ctx.convertYUV420ToRGB565())
|
| | | return false;
|
| | | }
|
| | |
|
| | | imgIdxes.clear();
|
| | | size_t offset = 0;
|
| | |
|
| | | cv::Mat rgbMat(cv::Size(ctx.width, ctx.height), CV_16UC1, ctx.frameRGB);
|
| | | for (st_ff_vect_t::const_iterator ffiter = ctx.faceFeatures.begin(); ffiter != ctx.faceFeatures.end(); ++ffiter)
|
| | | {
|
| | | const FaceRect& faceRect(ffiter->rect);
|
| | | cv::Mat roiMat1(rgbMat, cv::Rect(faceRect.leftTop.x, faceRect.leftTop.y, faceRect.rightBottom.x - faceRect.leftTop.x, faceRect.rightBottom.y - faceRect.leftTop.y));
|
| | | cv::Mat roiMat(roiMat1.clone()); // #todo copy data should be avoid!!!!
|
| | |
|
| | | NativeImgIdx imgidx;
|
| | | imgidx.offset = offset;
|
| | | imgidx.size = roiMat.total() * roiMat.elemSize();
|
| | | imgidx.type = MB_Frame::MBFT_RGB565;
|
| | | imgidx.width = roiMat.cols;
|
| | | imgidx.height = roiMat.rows;
|
| | |
|
| | | const size_t newSize = imgidx.offset + imgidx.size;
|
| | |
|
| | | //isContinuous
|
| | | if (newSize > buffImgMaxSize)
|
| | | {
|
| | | LOG_ERROR << "FaceCache::getFaceListImage buffImgMaxSize truncated" << LOG_ENDL;
|
| | | return false;
|
| | | }
|
| | |
|
| | | /*
|
| | | uint8_t* pbuf = buffImg + imgidx.offset;
|
| | | uint8_t* psrc = ctx.frameRGB + (ctx.width * faceRect.leftTop.y + faceRect.leftTop.x) * 2;
|
| | | for (int row = 0; row < faceRect.height(); row++)
|
| | | {
|
| | | memcpy(pbuf, psrc, imgidx.width * 2);
|
| | | pbuf += imgidx.width * 2;
|
| | | psrc += ctx.width * 2;
|
| | | }
|
| | | */
|
| | |
|
| | | uint8_t* pbuf = buffImg + imgidx.offset;
|
| | | memcpy(pbuf, roiMat.ptr(), imgidx.size);
|
| | |
|
| | | //{
|
| | | // static size_t f = 0;
|
| | | // char fname[50];
|
| | | // sprintf(fname, "/sdcard/face-%u.rgb565", ++f);
|
| | | // FILE *pFile = fopen(fname, "wb");
|
| | | // fwrite(pbuf, 1, imgidx.size, pFile);
|
| | | // fclose(pFile);
|
| | | // if (f > 20)exit(0);
|
| | | //}
|
| | |
|
| | | imgIdxes.push_back(imgidx);
|
| | | offset = newSize;
|
| | | }
|
| | |
|
| | | buffImgMaxSize = offset;
|
| | | return true;
|
| | | }
|
| | |
|
| | | #endif
|