JdydAlgorithnm.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. #include "JdydAlgorithnm.h"
  2. static ClassifyDectect classifyDectect;
  3. static DisconnectorDectect disconnectorDectect;
  4. static OilLevelDectect oilLevelDectect;
  5. static LightDectect lightDectect;
  6. static AirSwitchDectect airSwitchDectect;
  7. static ChangeoverSwitchDectect changeoverSwitchDectect;
  8. static IndoorDisconnectorDectect indoorDisconnectorDectect;
  9. static TriangleDisconnectorDectect triangleDisconnectorDectect;
  10. static MeterDectect meterDectect;
  11. static CharacterDectect characterDectect;
  12. static DisconnectorStateDectect disconnectorStateDectect;
  13. static ElectronPlateDectect electronPlateDectect;
  14. static NumberDectect numberDectect;
  15. static InstructionsDectect instructionsDectect;
  16. static ContactDectect contactDectect;
  17. static OperatingHandleStateDectect operatingHandleStateDectect;
  18. static PressplateDectect pressplateDectect;
  19. static PersonBehaviorDetect personBehaviorDetect;
  20. static CircleOffOnPlateDectect circleOffOnPlateDectect;
  21. static AppearanceClassifyDectect appearanceClassifyDectect;
  22. static InsulatorDetect insulatorDetect;
  23. bool JdydAlgorithnm::Init()
  24. {
  25. try
  26. {
  27. bool isCuda = false;
  28. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  29. classifyDectect.Init(isCuda);
  30. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("分类模型"));
  31. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  32. disconnectorDectect.Init(isCuda);
  33. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("隔离开关模型"));
  34. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  35. operatingHandleStateDectect.Init(isCuda);
  36. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("操作手柄模型"));
  37. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  38. personBehaviorDetect.Init(isCuda);
  39. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("安全防范模型"));
  40. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  41. pressplateDectect.Init(isCuda);
  42. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("压板模型"));
  43. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  44. oilLevelDectect.Init(isCuda);
  45. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("油位模型"));
  46. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  47. lightDectect.Init(isCuda);
  48. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("信号灯模型"));
  49. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  50. airSwitchDectect.Init(isCuda);
  51. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("空开模型"));
  52. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  53. changeoverSwitchDectect.Init(isCuda);
  54. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("旋转开关模型"));
  55. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  56. indoorDisconnectorDectect.Init(isCuda);
  57. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("竖直隔离开关模型"));
  58. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  59. triangleDisconnectorDectect.Init(isCuda);
  60. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("三角隔离开关模型"));
  61. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  62. meterDectect.Init(isCuda);
  63. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("仪表模型"));
  64. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  65. characterDectect.Init(isCuda);
  66. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("字符型模型"));
  67. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  68. disconnectorStateDectect.Init(isCuda);
  69. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("隔离开关室内状态模型"));
  70. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  71. electronPlateDectect.Init(isCuda);
  72. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("电子数字表盘模型"));
  73. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  74. numberDectect.Init(isCuda);
  75. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("数字识别模型"));
  76. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  77. instructionsDectect.Init(isCuda);
  78. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("标识识别模型"));
  79. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  80. contactDectect.Init(isCuda);
  81. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("连接点识别模型"));
  82. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  83. circleOffOnPlateDectect.Init(isCuda);
  84. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("圆盘分合储能模型"));
  85. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  86. appearanceClassifyDectect.Init(isCuda);
  87. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("外观识别模型"));
  88. QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
  89. insulatorDetect.Init(isCuda);
  90. YunDaISASImageRecognitionService::ConsoleLog(QStringLiteral("绝缘子识别模型"));
  91. }
  92. catch (const std::exception& ex)
  93. {
  94. YunDaISASImageRecognitionService::ConsoleLog(ex.what());
  95. }
  96. return true;
  97. }
  98. json JdydAlgorithnm::CallAlgorithnm(string pluginName, string filePath, string modelPath, int* roiVec, string pcArg)
  99. {
  100. cv::Mat img = cv::imread(filePath);
  101. int imgWidth = (roiVec[4] - roiVec[0])<1 || (roiVec[4] - roiVec[0]) > img.cols ? img.cols: (roiVec[4] - roiVec[0]);
  102. int imgheight =(roiVec[5] - roiVec[1])<1 || (roiVec[5] - roiVec[1]) > img.rows ? img.rows : (roiVec[5] - roiVec[1]);
  103. int topX = roiVec[0] <0 || roiVec[0]> img.cols ? 0: roiVec[0];
  104. int topY = roiVec[1] < 0 || roiVec[1]> img.rows ? 0 : roiVec[1];
  105. if (topX+ imgWidth> img.cols)
  106. {
  107. topX = 0;
  108. imgWidth = img.cols;
  109. }
  110. if (topY+ imgheight> img.rows)
  111. {
  112. topY = 0;
  113. imgheight = img.rows;
  114. }
  115. cv::Rect rect(topX, topY, imgWidth, imgheight);
  116. cv::Mat ROI = img(rect);
  117. string tempPath = "test.png";
  118. string rstStr = "";
  119. vector<Output> result;
  120. vector<Output2> result2;
  121. string rstValue = "";
  122. int flag = -1;
  123. vector <string> rstStrArr;
  124. vector<vector<int>> rstRoiArr;
  125. if (pluginName=="Appearance") //外观识别
  126. {
  127. //Todo 外观识别
  128. if (appearanceClassifyDectect.Detect(ROI, result2))
  129. {
  130. if (YunDaISASImageRecognitionService::GetIsShowDectect())
  131. {
  132. cv::Mat drawROI;
  133. ROI.copyTo(drawROI);
  134. appearanceClassifyDectect.drawPred(drawROI, result2);
  135. imwrite("test.png", drawROI);
  136. YunDaISASImageRecognitionService::SetImage(QString::fromStdString(tempPath));
  137. }
  138. }
  139. if (1 <= result2.size())
  140. {
  141. float confidenceMax = 0;
  142. int confidenceMaxId = 0;
  143. int closestCenterPoint = ROI.cols + ROI.rows;
  144. int centerX = ROI.cols / 2;
  145. int centerY = ROI.rows / 2;
  146. int maxCenterBoxId = 0;
  147. float instructionsConfidenceMax = 0;
  148. int instructionsConfidenceMaxId = -1;
  149. float pluginNameConfidenceMax = 0;
  150. int pluginNameId = -1;
  151. for (size_t i = 0; i < result2.size(); i++)
  152. {
  153. int absX = cv::abs((result2[i].box.x + result2[i].box.width / 2) - centerX);
  154. int absY = cv::abs((result2[i].box.y + result2[i].box.height / 2) - centerY);
  155. if (appearanceClassifyDectect.className[result2[i].id] == appearanceClassifyDectect.instructionsName)
  156. {
  157. if (result2[i].confidence > instructionsConfidenceMax)
  158. {
  159. instructionsConfidenceMax = result2[i].confidence;
  160. instructionsConfidenceMaxId = i;
  161. }
  162. }
  163. else if (pluginName.size() > 0 && appearanceClassifyDectect.className[result2[i].id] == pluginName)
  164. {
  165. if (result2[i].confidence > pluginNameConfidenceMax)
  166. {
  167. pluginNameConfidenceMax = result2[i].confidence;
  168. pluginNameId = i;
  169. }
  170. }
  171. else
  172. {
  173. if (result2[i].confidence > confidenceMax)
  174. {
  175. confidenceMax = result2[i].confidence;
  176. confidenceMaxId = i;
  177. }
  178. if (absX + absY < closestCenterPoint)
  179. {
  180. closestCenterPoint = absX + absY;
  181. maxCenterBoxId = i;
  182. }
  183. }
  184. vector<int> vecRec;
  185. vecRec.push_back(result2[i].box.x);
  186. vecRec.push_back(result2[i].box.y);
  187. vecRec.push_back(result2[i].box.width);
  188. vecRec.push_back(result2[i].box.height);
  189. rstRoiArr.push_back(vecRec);
  190. rstStrArr.push_back(appearanceClassifyDectect.className[result2[i].id]);
  191. }
  192. string instructionsDectectResultStr = "";
  193. if (instructionsConfidenceMaxId != -1)
  194. {
  195. IDetection::DectectResult dectectResult = instructionsDectect.GetStateResult(ROI, result2[instructionsConfidenceMaxId].box);
  196. instructionsDectectResultStr = dectectResult.m_sValue;
  197. }
  198. AppearanceGetMaxConfidenceRecoResult(rstStr, rstValue, instructionsDectectResultStr, result2, maxCenterBoxId, pluginNameId, ROI);
  199. }
  200. else
  201. {
  202. if (pluginName.size() > 0)
  203. {
  204. for (size_t i = 0; i < appearanceClassifyDectect.className.size(); i++)
  205. {
  206. rstStr = "appearanceDetect_";
  207. if (appearanceClassifyDectect.className[i] == pluginName)
  208. {
  209. Output pluginNameOutput;
  210. pluginNameOutput.box.x = 0;
  211. pluginNameOutput.box.y = 0;
  212. pluginNameOutput.box.width = ROI.cols;
  213. pluginNameOutput.box.height = ROI.rows;
  214. pluginNameOutput.id = i;
  215. pluginNameOutput.confidence = 0.99;
  216. result.push_back(pluginNameOutput);
  217. int pluginNameId = 0;
  218. string instructionsDectectResultStr = "";
  219. int maxCenterBoxId = 0;
  220. AppearanceGetMaxConfidenceRecoResult(rstStr, rstValue, instructionsDectectResultStr, result2, maxCenterBoxId, pluginNameId, ROI);
  221. }
  222. }
  223. }
  224. }
  225. if (rstStr.size() > 300)
  226. {
  227. rstStr = "";
  228. }
  229. }
  230. else
  231. {
  232. if (classifyDectect.Detect(ROI, result))
  233. {
  234. if (YunDaISASImageRecognitionService::GetIsShowDectect())
  235. {
  236. cv::Mat drawROI;
  237. ROI.copyTo(drawROI);
  238. classifyDectect.drawPred(drawROI, result);
  239. imwrite("test.png", drawROI);
  240. YunDaISASImageRecognitionService::SetImage(QString::fromStdString(tempPath));
  241. }
  242. }
  243. if (1 <= result.size())
  244. {
  245. float confidenceMax = 0;
  246. int confidenceMaxId = 0;
  247. int closestCenterPoint = ROI.cols + ROI.rows;
  248. int centerX = ROI.cols / 2;
  249. int centerY = ROI.rows / 2;
  250. int maxCenterBoxId = 0;
  251. float instructionsConfidenceMax = 0;
  252. int instructionsConfidenceMaxId = -1;
  253. float pluginNameConfidenceMax = 0;
  254. int pluginNameId = -1;
  255. for (size_t i = 0; i < result.size(); i++)
  256. {
  257. int absX = cv::abs((result[i].box.x + result[i].box.width / 2) - centerX);
  258. int absY = cv::abs((result[i].box.y + result[i].box.height / 2) - centerY);
  259. if (classifyDectect.className[result[i].id] == classifyDectect.instructionsName)
  260. {
  261. if (result[i].confidence > instructionsConfidenceMax)
  262. {
  263. instructionsConfidenceMax = result[i].confidence;
  264. instructionsConfidenceMaxId = i;
  265. }
  266. }
  267. else if (pluginName.size() > 0 && classifyDectect.className[result[i].id] == pluginName)
  268. {
  269. if (result[i].confidence > pluginNameConfidenceMax)
  270. {
  271. pluginNameConfidenceMax = result[i].confidence;
  272. pluginNameId = i;
  273. }
  274. }
  275. else
  276. {
  277. if (result[i].confidence > confidenceMax)
  278. {
  279. confidenceMax = result[i].confidence;
  280. confidenceMaxId = i;
  281. }
  282. if (absX + absY < closestCenterPoint)
  283. {
  284. closestCenterPoint = absX + absY;
  285. maxCenterBoxId = i;
  286. }
  287. }
  288. vector<int> vecRec;
  289. vecRec.push_back(result[i].box.x);
  290. vecRec.push_back(result[i].box.y);
  291. vecRec.push_back(result[i].box.width);
  292. vecRec.push_back(result[i].box.height);
  293. rstRoiArr.push_back(vecRec);
  294. rstStrArr.push_back(classifyDectect.className[result[i].id]);
  295. }
  296. /*if (!YunDaISASImageRecognitionService::GetReconginzeStratgy())
  297. {
  298. maxCenterBoxId = confidenceMaxId;
  299. }*/
  300. string instructionsDectectResultStr = "";
  301. if (instructionsConfidenceMaxId != -1)
  302. {
  303. IDetection::DectectResult dectectResult = instructionsDectect.GetStateResult(ROI, result[instructionsConfidenceMaxId].box);
  304. instructionsDectectResultStr = dectectResult.m_sValue;
  305. }
  306. /* string tempResult = "";
  307. string tempResultValue = "";*/
  308. GetMaxConfidenceRecoResult(rstStr, rstValue, instructionsDectectResultStr, result, maxCenterBoxId, pluginNameId, ROI);
  309. /* rstStr = tempResult;
  310. rstValue = tempResultValue;*/
  311. }
  312. else
  313. {
  314. if (pluginName.size() > 0)
  315. {
  316. for (size_t i = 0; i < classifyDectect.className.size(); i++)
  317. {
  318. if (classifyDectect.className[i] == pluginName)
  319. {
  320. Output pluginNameOutput;
  321. pluginNameOutput.box.x = 0;
  322. pluginNameOutput.box.y = 0;
  323. pluginNameOutput.box.width = ROI.cols;
  324. pluginNameOutput.box.height = ROI.rows;
  325. pluginNameOutput.id = i;
  326. pluginNameOutput.confidence = 0.99;
  327. result.push_back(pluginNameOutput);
  328. int pluginNameId = 0;
  329. string instructionsDectectResultStr = "";
  330. int maxCenterBoxId = 0;
  331. GetMaxConfidenceRecoResult(rstStr, rstValue, instructionsDectectResultStr, result, maxCenterBoxId, pluginNameId, ROI);
  332. }
  333. }
  334. }
  335. }
  336. if (rstStr.size() > 300)
  337. {
  338. rstStr = "";
  339. }
  340. }
  341. json resultJson = { {"flag", flag}, {"result" , rstStr}, {"resultValue" , rstValue},{"results" , rstStrArr} ,{"resultRois",rstRoiArr}};
  342. return resultJson;
  343. }
  344. void JdydAlgorithnm::GetMaxConfidenceRecoResult(string &tempResult, string &tempResultValue, const string instructionsDectectResultStr,vector<Output> result, int maxCenterBoxId,const int pluginNameId,const cv::Mat ROI)
  345. {
  346. if (pluginNameId > -1)
  347. {
  348. maxCenterBoxId = pluginNameId;
  349. }
  350. cv::Rect boxTemp = result[maxCenterBoxId].box;
  351. if (boxTemp.x<0 ||
  352. boxTemp.y < 0 ||
  353. boxTemp.x + boxTemp.width>ROI.cols ||
  354. boxTemp.y + boxTemp.height>ROI.rows)
  355. {
  356. boxTemp.x = 0;
  357. boxTemp.y = 0;
  358. boxTemp.width = ROI.cols;
  359. boxTemp.height = ROI.rows;
  360. }
  361. result[maxCenterBoxId].box = boxTemp;
  362. if (classifyDectect.className[result[maxCenterBoxId].id] == "disconnector")//隔离开关
  363. {
  364. IDetection::DectectResult dectectResultVec = disconnectorDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  365. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  366. }
  367. else if (classifyDectect.className[result[maxCenterBoxId].id] == "oil_level")//油位
  368. {
  369. IDetection::DectectResult dectectResultVec = oilLevelDectect.GetDigitResult(ROI, result[maxCenterBoxId].box);
  370. if (dectectResultVec.m_sValue != "")
  371. {
  372. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  373. }
  374. else {
  375. tempResult = classifyDectect.className[result[maxCenterBoxId].id];
  376. }
  377. tempResultValue = std::to_string(dectectResultVec.m_dValue);
  378. }
  379. else if (classifyDectect.className[result[maxCenterBoxId].id] == "meter")//指针表盘
  380. {
  381. auto dectectResults = meterDectect.GetDigitResults(ROI, result[maxCenterBoxId].box);
  382. if (dectectResults.size() > 0)
  383. {
  384. for (size_t i = 0; i < dectectResults.size(); i++)
  385. {
  386. string tempResultItem = "";
  387. string tempResultValueItem = "";
  388. if (dectectResults[i].m_sValue != "")
  389. {
  390. tempResultItem = "meter_" + dectectResults[i].m_sValue;
  391. }
  392. else {
  393. tempResultItem = classifyDectect.className[result[maxCenterBoxId].id];
  394. }
  395. tempResultValueItem = std::to_string(dectectResults[i].m_dValue);
  396. if (tempResultValueItem != "" && tempResultItem != "")
  397. {
  398. if (tempResult == "")
  399. {
  400. tempResult += tempResultItem;
  401. tempResultValue += tempResultValueItem;
  402. }
  403. else
  404. {
  405. tempResult += ";";
  406. tempResult += tempResultItem;
  407. tempResultValue += ";";
  408. tempResultValue += tempResultValueItem;
  409. }
  410. }
  411. }
  412. }
  413. else {
  414. tempResult = "meter_" + meterDectect.GetDigitResult(ROI, result[maxCenterBoxId].box).m_sValue;
  415. }
  416. }
  417. else if (classifyDectect.className[result[maxCenterBoxId].id] == "changeover_switch")
  418. {
  419. IDetection::DectectResult dectectResultVec = changeoverSwitchDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  420. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  421. }
  422. else if (classifyDectect.className[result[maxCenterBoxId].id] == "pressplate")
  423. {
  424. IDetection::DectectResult dectectResultVec = pressplateDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  425. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  426. }
  427. else if (classifyDectect.className[result[maxCenterBoxId].id] == "disconnector_state")
  428. {
  429. IDetection::DectectResult dectectResultVec = disconnectorStateDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  430. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  431. }
  432. else if (classifyDectect.className[result[maxCenterBoxId].id] == "light")
  433. {
  434. IDetection::DectectResult dectectResultVec = lightDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  435. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  436. }
  437. else if (classifyDectect.className[result[maxCenterBoxId].id] == "air_switch")
  438. {
  439. IDetection::DectectResult dectectResultVec = airSwitchDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  440. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  441. }
  442. else if (classifyDectect.className[result[maxCenterBoxId].id] == "character")
  443. {
  444. IDetection::DectectResult dectectResultVec = characterDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  445. if (characterDectect.GetStateResults().size() > 0)
  446. {
  447. string tempResultItem = "";
  448. for (size_t i = 0; i < characterDectect.GetStateResults().size(); i++)
  449. {
  450. if (tempResultItem == "")
  451. {
  452. tempResultItem += "character_" + characterDectect.GetStateResults()[i].m_sValue;
  453. }
  454. else
  455. {
  456. tempResultItem += ";";
  457. tempResultItem += "character_" + characterDectect.GetStateResults()[i].m_sValue;
  458. }
  459. }
  460. tempResult = tempResultItem;
  461. }
  462. else
  463. {
  464. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  465. }
  466. }
  467. else if (classifyDectect.className[result[maxCenterBoxId].id] == "indoor_disconnector")
  468. {
  469. IDetection::DectectResult dectectResultVec = indoorDisconnectorDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  470. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  471. }
  472. else if (classifyDectect.className[result[maxCenterBoxId].id] == "triangle_disconnector")
  473. {
  474. IDetection::DectectResult dectectResultVec = triangleDisconnectorDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  475. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  476. }
  477. else if (classifyDectect.className[result[maxCenterBoxId].id] == "electron_plate")//电子数字盘
  478. {
  479. auto dectectResults = electronPlateDectect.GetDigitResults(ROI, result[maxCenterBoxId].box);
  480. if (dectectResults.size() > 0)
  481. {
  482. for (size_t i = 0; i < dectectResults.size(); i++)
  483. {
  484. string tempResultItem = "";
  485. string tempResultValueItem = "";
  486. if (dectectResults[i].m_sValue != "digit")
  487. {
  488. tempResultItem = "electron_plate_" + dectectResults[i].m_sValue;
  489. //tempResult = tempResultItem;
  490. }
  491. else {
  492. tempResultItem = "electron_plate_" + dectectResults[i].m_sValue;
  493. tempResultValueItem = std::to_string(dectectResults[i].m_dValue);
  494. }
  495. if (tempResultItem != "")
  496. {
  497. if (tempResult == "")
  498. {
  499. tempResult += tempResultItem;
  500. tempResultValue += tempResultValueItem;
  501. }
  502. else
  503. {
  504. tempResult += ";";
  505. tempResult += tempResultItem;
  506. tempResultValue += ";";
  507. tempResultValue += tempResultValueItem;
  508. }
  509. }
  510. }
  511. }
  512. else {
  513. auto resultStateValue = electronPlateDectect.GetDigitResult(ROI, result[maxCenterBoxId].box).m_sValue;
  514. if (resultStateValue == "") {
  515. tempResult = "electron_plate";
  516. }
  517. else {
  518. tempResult = "electron_plate_" + resultStateValue;
  519. }
  520. }
  521. }
  522. else if (classifyDectect.className[result[maxCenterBoxId].id] == "contact")
  523. {
  524. IDetection::DectectResult dectectResultVec = contactDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  525. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  526. }
  527. else if (classifyDectect.className[result[maxCenterBoxId].id] == "operating_handle")
  528. {
  529. IDetection::DectectResult dectectResultVec = operatingHandleStateDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  530. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  531. }
  532. else if (classifyDectect.className[result[maxCenterBoxId].id] == "person")
  533. {
  534. IDetection::DectectResult dectectResultVec = personBehaviorDetect.GetStateResult(ROI, result[maxCenterBoxId].box);
  535. //if (dectectResultVec.m_sValue != "")
  536. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_";
  537. /*{
  538. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  539. }
  540. else {
  541. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_";
  542. }*/
  543. }
  544. else if (classifyDectect.className[result[maxCenterBoxId].id] == "circle_off_on_plate")
  545. {
  546. IDetection::DectectResult dectectResultVec = circleOffOnPlateDectect.GetStateResult(ROI, result[maxCenterBoxId].box);
  547. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  548. }
  549. else if (classifyDectect.className[result[maxCenterBoxId].id] == "fire")
  550. {
  551. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_";
  552. }
  553. else if (classifyDectect.className[result[maxCenterBoxId].id] == "smoke")
  554. {
  555. tempResult = classifyDectect.className[result[maxCenterBoxId].id] + "_";
  556. }
  557. }
  558. //外观识别 2023.7.18
  559. ////////////////////
  560. void JdydAlgorithnm::AppearanceGetMaxConfidenceRecoResult(string& tempResult, string& tempResultValue, const string instructionsDectectResultStr, vector<Output2> result2, int maxCenterBoxId, const int pluginNameId, const cv::Mat ROI)
  561. {
  562. if (pluginNameId > -1)
  563. {
  564. maxCenterBoxId = pluginNameId;
  565. }
  566. cv::Rect boxTemp = result2[maxCenterBoxId].box;
  567. if (boxTemp.x<0 ||
  568. boxTemp.y < 0 ||
  569. boxTemp.x + boxTemp.width>ROI.cols ||
  570. boxTemp.y + boxTemp.height>ROI.rows)
  571. {
  572. boxTemp.x = 0;
  573. boxTemp.y = 0;
  574. boxTemp.width = ROI.cols;
  575. boxTemp.height = ROI.rows;
  576. }
  577. result2[maxCenterBoxId].box = boxTemp;
  578. if (appearanceClassifyDectect.className[result2[maxCenterBoxId].id] == "oil")
  579. {
  580. tempResult = "appearanceDetect_" + appearanceClassifyDectect.className[result2[maxCenterBoxId].id] + "_";
  581. }
  582. else if (appearanceClassifyDectect.className[result2[maxCenterBoxId].id] == "insulator")
  583. {
  584. IDetection::DectectResult dectectResultVec = insulatorDetect.GetStateResult(ROI, result2[maxCenterBoxId].box);
  585. if (dectectResultVec.m_sValue != "")
  586. {
  587. tempResult = "appearanceDetect_" + appearanceClassifyDectect.className[result2[maxCenterBoxId].id] + "_" + dectectResultVec.m_sValue;
  588. }
  589. else {
  590. tempResult = "appearanceDetect_" + appearanceClassifyDectect.className[result2[maxCenterBoxId].id] + "_";
  591. }
  592. }
  593. else if (appearanceClassifyDectect.className[result2[maxCenterBoxId].id] == "person")
  594. {
  595. tempResult = "appearanceDetect_" + appearanceClassifyDectect.className[result2[maxCenterBoxId].id] + "__";
  596. }
  597. else if(appearanceClassifyDectect.className[result2[maxCenterBoxId].id] == "")
  598. {
  599. tempResult = "appearanceDetect_";
  600. }
  601. }
  602. ClassifyDectect& JdydAlgorithnm::GetClassifyDectectInstance() {
  603. return classifyDectect;
  604. }
  605. DisconnectorDectect& JdydAlgorithnm::GetdisconnectorDectectInstance() {
  606. return disconnectorDectect;
  607. }
  608. OilLevelDectect& JdydAlgorithnm::GetoilLevelDectectInstance() {
  609. return oilLevelDectect;
  610. }
  611. LightDectect& JdydAlgorithnm::GetlightDectectInstance(){
  612. return lightDectect;
  613. }
  614. AirSwitchDectect& JdydAlgorithnm::GetairSwitchDectectInstance() {
  615. return airSwitchDectect;
  616. }
  617. ChangeoverSwitchDectect& JdydAlgorithnm::GetchangeoverSwitchDectectInstance() {
  618. return changeoverSwitchDectect;
  619. }
  620. IndoorDisconnectorDectect& JdydAlgorithnm::GetindoorDisconnectorDectectInstance() {
  621. return indoorDisconnectorDectect;
  622. }
  623. MeterDectect& JdydAlgorithnm::GetmeterDectectInstance() {
  624. return meterDectect;
  625. }
  626. CharacterDectect& JdydAlgorithnm::GetcharacterDectectInstance() {
  627. return characterDectect;
  628. }
  629. DisconnectorStateDectect& JdydAlgorithnm::GetdisconnectorStateDectectInstance() {
  630. return disconnectorStateDectect;
  631. }
  632. ElectronPlateDectect& JdydAlgorithnm::GetelectronPlateDectectInstance() {
  633. return electronPlateDectect;
  634. }
  635. NumberDectect& JdydAlgorithnm::GeNumberDectectInstance()
  636. {
  637. return numberDectect;
  638. }
  639. OperatingHandleStateDectect& JdydAlgorithnm::GetoperatingHandleStateDectectInstance()
  640. {
  641. return operatingHandleStateDectect;
  642. }
  643. PressplateDectect& JdydAlgorithnm::GetpressplateDectectInstance()
  644. {
  645. return pressplateDectect;
  646. }
  647. PersonBehaviorDetect& JdydAlgorithnm::GetpersonBehaviorDetectInstance()
  648. {
  649. return personBehaviorDetect;
  650. }
  651. CircleOffOnPlateDectect& JdydAlgorithnm::GetcircleOffOnPlateDectectInstance()
  652. {
  653. return circleOffOnPlateDectect;
  654. }
  655. AppearanceClassifyDectect& JdydAlgorithnm::GetAppearanceClassifyDectectInstance()
  656. {
  657. return appearanceClassifyDectect;
  658. }
  659. InsulatorDetect& JdydAlgorithnm::GetInsulatorDetectInstance()
  660. {
  661. return insulatorDetect;
  662. }