| | |
| | | #include <basic/util/opencv/CvUtil.h> |
| | | #include <QJsonDocument> |
| | | #include <QJsonObject> |
| | | |
| | | #define GETSCORE(IDENT) appPref.getFloatData(IDENT) == -1 ? 95 : appPref.getFloatData(IDENT); |
| | | |
| | | //************************************ |
| | |
| | | } |
| | | |
| | | //todo appPref.getStringData("face.detect.proxy") |
| | | FaceRpcElement::FaceRpcElement(string shareMemoryName,const SdkRule& rule) : |
| | | FaceRpcElement::FaceRpcElement(string shareMemoryName, const SdkRule &rule) : |
| | | //#todo |
| | | rpcClient(appPref.getStringData("faceDete.proxy"), appPref.getStringData("faceDete.ip"), |
| | | appPref.getIntData("faceDete.port"), "tcp"), |
| | |
| | | // rpcClient("faceServer","",10002,"tcp"), |
| | | sharedMemory(nullptr), |
| | | trackingTrigger(nullptr), |
| | | m_sdkRule(rule) |
| | | { |
| | | m_sdkRule(rule), |
| | | m_bIsMask(true), |
| | | m_bSetWH(false) { |
| | | sharedMemory = new QSharedMemory(QString(shareMemoryName.c_str())); |
| | | if (!sharedMemory->create(4608 * 2592 * 4)) { |
| | | sharedMemory->attach(); |
| | |
| | | |
| | | // string t_camIdex = getProperty("dev_id"); |
| | | //#todo |
| | | string t_camIdex; |
| | | if (shareMemoryName.find("/")) { |
| | | string_replace(shareMemoryName, "//", "/"); |
| | | auto dev_pos = shareMemoryName.find("/cut/") + 5; |
| | | auto ch_pos = shareMemoryName.find("/", dev_pos) + 1; |
| | | auto str_device_id = shareMemoryName.substr(dev_pos, ch_pos - dev_pos - 1); |
| | | auto str_ch_id = shareMemoryName.substr(ch_pos, shareMemoryName.find("/", ch_pos) - ch_pos); |
| | | t_camIdex.append(str_device_id).append(str_ch_id); |
| | | } else { |
| | | t_camIdex = shareMemoryName.substr(0, shareMemoryName.rfind("faceRpc")); |
| | | } |
| | | // string t_camIdex; |
| | | // if (shareMemoryName.find("/")) { |
| | | // string_replace(shareMemoryName, "//", "/"); |
| | | // auto dev_pos = shareMemoryName.find("/cut/") + 5; |
| | | // auto ch_pos = shareMemoryName.find("/", dev_pos) + 1; |
| | | // auto str_device_id = shareMemoryName.substr(dev_pos, ch_pos - dev_pos - 1); |
| | | // auto str_ch_id = shareMemoryName.substr(ch_pos, shareMemoryName.find("/", ch_pos) - ch_pos); |
| | | // t_camIdex.append(str_device_id).append(str_ch_id); |
| | | // } else { |
| | | // t_camIdex = shareMemoryName.substr(0, shareMemoryName.rfind("faceRpc")); |
| | | // } |
| | | |
| | | float t_score = m_sdkRule.nQuality; |
| | | |
| | | DBG(" TESTCODE getValue" << t_camIdex << " " << t_score << " " << t_score / 100); |
| | | DBG(" TESTCODE getValue" << shareMemoryName << " " << t_score << " " << t_score / 100); |
| | | |
| | | t_score = t_score / 100; |
| | | |
| | | trackingTrigger = new TrackingTrigger(t_score); |
| | | setMask(m_sdkRule.strAreas.toStdString()); |
| | | // setMask(m_sdkRule.strAreas.toStdString()); |
| | | } |
| | | |
| | | FaceRpcElement::~FaceRpcElement() { |
| | |
| | | } |
| | | |
| | | void FaceRpcElement::threadFunc() { |
| | | INFO("MYH Run Here"); |
| | | // ClockTimer ct("FaceRpcElement::threadFunc"); |
| | | // { |
| | | // |
| | | // string string1(AppUtil::getTimeString() + "-ff2" + getProperty("time") + ".jpg"); |
| | | // cv::imwrite(string1, image); |
| | | // } |
| | | if(!isInWeek(m_sdkRule.weekRuleVec)) |
| | | if (!isInWeek(m_sdkRule.weekRuleVec)) { |
| | | ERR("In Week"); |
| | | return; |
| | | } |
| | | triggerMats.clear(); |
| | | triggerFaces.clear(); |
| | | triggerScoredRects.clear(); |
| | |
| | | int y = face.rcFace.top; |
| | | int w = face.rcFace.right - face.rcFace.left; |
| | | int h = face.rcFace.bottom - face.rcFace.top; |
| | | QRect re(x,y,w,h); |
| | | QRect re(x, y, w, h); |
| | | QPoint center = re.center(); |
| | | if(!mPolygon.containsPoint(center,Qt::OddEvenFill)) |
| | | { |
| | | if (m_bIsMask && !mPolygon.containsPoint(center, Qt::OddEvenFill)) { |
| | | ERR("m_bIsMask :" << m_bIsMask) |
| | | return; |
| | | } |
| | | scoredRect.rect = {x, y, w, h}; |
| | |
| | | trackingTrigger->getLastRect().properties["smile"] = to_string(property.smile_level); |
| | | trackingTrigger->getLastRect().properties["race"] = to_string(property.race); |
| | | trackingTrigger->getLastRect().properties["time"] = getProperty("time"); |
| | | |
| | | trackingTrigger->getLastRect().properties["detectscore"] = scoredRect.score; |
| | | trackingTrigger->getLastRect().properties["imgKey"] = getProperty("imgKey"); |
| | | INFO("FaceRpcElement SaveToES: " << getProperty("imgKey")); |
| | | triggerFaces.push_back(face); |
| | | triggerMats.push_back(image( |
| | | CvUtil::zoomRectEqual(scoredRect.rect, 1.5, 1.5) & cv::Rect(0, 0, image.cols, image.rows)).clone()); |
| | | triggerScoredRects.push_back(trackingTrigger->getLastRect()); |
| | | } else { |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | // DBG("trackingTrigger->triggerOnce(scoredRect) is false "); |
| | | } |
| | | } |
| | | if (faces.empty()) { |
| | | INFO("No Face Find: " << getProperty("imgKey")); |
| | | } |
| | | trackingTrigger->triggerLine(); |
| | | // DBG("faces.size " << faces.size()); |
| | |
| | | image = cv::Mat(value.rows, value.cols, CV_8UC3, sharedMemory->data()); |
| | | } |
| | | value.copyTo(image); |
| | | if (!m_bSetWH) { |
| | | setMask(m_sdkRule.strAreas.toStdString()); |
| | | m_bSetWH = true; |
| | | } |
| | | } |
| | | |
| | | bool FaceRpcElement::getTriggerState() const { |
| | | return m_triggerElement.getTriggerState(); |
| | | } |
| | | void FaceRpcElement::setMask(std::string mask) |
| | | { |
| | | |
| | | void FaceRpcElement::setMask(std::string mask) { |
| | | QJsonArray arrayAreas = getJsonArrayFromQString(QString::fromStdString(mask)); |
| | | if(arrayAreas.isEmpty()) |
| | | { |
| | | if (arrayAreas.isEmpty()) { |
| | | m_bIsMask = false; |
| | | return;//do not detect |
| | | } |
| | | for(int i = 0;i < arrayAreas.size();++i) |
| | | { |
| | | float sizeW = (float) appPref.getIntData(m_sdkRule.strCamId.toStdString() + "width") / 480; |
| | | float sizeH = (float) appPref.getIntData(m_sdkRule.strCamId.toStdString() + "height") / 270; |
| | | for (int i = 0; i < arrayAreas.size(); ++i) { |
| | | QJsonValue jsonValue = arrayAreas[i]; |
| | | QJsonObject obj = jsonValue.toObject(); |
| | | int x = obj.value("x").toDouble()*4; |
| | | int y = obj.value("y").toDouble()*4; |
| | | mPolygon<<(QPoint(x,y)); |
| | | int x = obj.value("x").toDouble() * sizeW; |
| | | int y = obj.value("y").toDouble() * sizeH; |
| | | mPolygon << (QPoint(x, y)); |
| | | DBG("width=" << sizeW); |
| | | DBG("height=" << sizeH); |
| | | |
| | | } |
| | | } |
| | | QJsonArray FaceRpcElement::getJsonArrayFromQString(const QString& strJson) |
| | | { |
| | | |
| | | QJsonArray FaceRpcElement::getJsonArrayFromQString(const QString &strJson) { |
| | | QJsonDocument jsonDocument = QJsonDocument::fromJson(strJson.toLocal8Bit()); |
| | | if( jsonDocument.isNull() ){ |
| | | DBG("please check the string"<< strJson.toStdString()); |
| | | if (jsonDocument.isNull()) { |
| | | DBG("please check the string" << strJson.toStdString()); |
| | | return QJsonArray(); |
| | | } |
| | | QJsonArray jsonArray = jsonDocument.array(); |
| | | return jsonArray; |
| | | } |
| | | bool FaceRpcElement::isInWeek(const std::vector<LActRuleWeekRecord>& ruleWeek) |
| | | { |
| | | |
| | | bool FaceRpcElement::isInWeek(const std::vector<LActRuleWeekRecord> &ruleWeek) { |
| | | |
| | | int nWeek = QDate::currentDate().dayOfWeek(); |
| | | for(int i = 0;i < ruleWeek.size();++i) |
| | | { |
| | | if(ruleWeek[i].m_nType == nWeek) |
| | | { |
| | | for (int i = 0; i < ruleWeek.size(); ++i) { |
| | | if (ruleWeek[i].m_nType == nWeek) { |
| | | QString strCurrent = QDateTime::currentDateTime().toString("hh:mm"); |
| | | if(strCurrent >= ruleWeek[i].m_strBegin && strCurrent <= ruleWeek[i].m_strEnd) |
| | | { |
| | | return true; |
| | | if (strCurrent >= ruleWeek[i].m_strBegin && strCurrent <= ruleWeek[i].m_strEnd) { |
| | | return true; |
| | | } |
| | | } |
| | | } |