프로젝트

일반

사용자정보

개정판 192f3cc0

ID192f3cc025393997a3de3afac459877a401f7f7e
상위 5e36f3a9
하위 7bc82980

gaqhf 이(가) 약 5년 전에 추가함

dev issue #503 : detectOPCOnPid

Change-Id: Idb43d294553467db7e6c487eb108f993fb674453

차이점 보기:

DTI_PID/DTI_PID/RecognitionDialog.py
964 964
                    connectionPoint = Worker.getCalculatedConnectionPoint(symbolConnectionPoint, symbolRotatedAngle, sw,
965 965
                                                                          sh, sow, soh, flipped)
966 966

  
967
                    # # For OPC
968
                    # drawing_area = app_doc_data.getArea('Drawing')
969
                    # if drawing_area is not None and (symbolType == "Piping OPC\'s" or symbolType == "Instrument OPC\'s"):
970
                    #     customMatch = worker.detectOPCOnPid(drawing_area, symGray)
971
                    #     if customMatch and len(customMatch) > 0:
972
                    #         for custom in customMatch:
973
                    #             hitRate = custom[0]
974
                    #             searchedItemSp = (custom[1][0] + round(offsetDrawingArea[0]), custom[1][1] + round(offsetDrawingArea[1]))
975
                    #
976
                    #             is_add = True
977
                    #             for searched in searchedSymbolList:
978
                    #                 if Worker.IsOverlap((searchedItemSp[0], searchedItemSp[1], sw, sh), (
979
                    #                         searched.getSp()[0], searched.getSp()[1], searched.getWidth(),
980
                    #                         searched.getHeight())):
981
                    #                     if searched.getHitRate() > hitRate:
982
                    #                         is_add = False
983
                    #                     else:
984
                    #                         searchedSymbolList.remove(searched)
985
                    #                         break
986
                    #
987
                    #             if is_add:
988
                    #                 threadLock.acquire()
989
                    #                 foundSymbolCount = foundSymbolCount + 1
990
                    #                 Worker.addSearchedSymbol(symbolName, symbolType,
991
                    #                                          searchedItemSp, sw, sh, symbolThreshold, symbolMinMatchCount,
992
                    #                                          hitRate, symbolRotatedAngle,
993
                    #                                          isDetectOnOrigin, symbolRotateCount, symbolOcrOption,
994
                    #                                          isContainChild,
995
                    #                                          originalPoint, connectionPoint, baseSymbol, additionalSymbol,
996
                    #                                          isExceptDetect, detectFlip=1 if flipped else 0,
997
                    #                                          hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
998
                    #                 threadLock.release()
967
                    # For OPC
968
                    drawing_area = app_doc_data.getArea('Drawing')
969
                    if drawing_area is not None and (symbolType == "Piping OPC\'s" or symbolType == "Instrument OPC\'s"):
970
                        customMatch = worker.detectOPCOnPid(drawing_area, symGray)
971
                        if customMatch and len(customMatch) > 0:
972
                            for custom in customMatch:
973
                                hitRate = custom[0]
974
                                searchedItemSp = (custom[1][0] + round(offsetDrawingArea[0]), custom[1][1] + round(offsetDrawingArea[1]))
975

  
976
                                is_add = True
977
                                for searched in searchedSymbolList:
978
                                    if Worker.IsOverlap((searchedItemSp[0], searchedItemSp[1], sw, sh), (
979
                                            searched.getSp()[0], searched.getSp()[1], searched.getWidth(),
980
                                            searched.getHeight())):
981
                                        if searched.getHitRate() > hitRate:
982
                                            is_add = False
983
                                        else:
984
                                            searchedSymbolList.remove(searched)
985
                                            break
986

  
987
                                if is_add:
988
                                    threadLock.acquire()
989
                                    foundSymbolCount = foundSymbolCount + 1
990
                                    Worker.addSearchedSymbol(symbolName, symbolType,
991
                                                             searchedItemSp, sw, sh, symbolThreshold, symbolMinMatchCount,
992
                                                             hitRate, symbolRotatedAngle,
993
                                                             isDetectOnOrigin, symbolRotateCount, symbolOcrOption,
994
                                                             isContainChild,
995
                                                             originalPoint, connectionPoint, baseSymbol, additionalSymbol,
996
                                                             isExceptDetect, detectFlip=1 if flipped else 0,
997
                                                             hasInstrumentLabel=hasInstrumentLabel, text_area=text_area)
998
                                    threadLock.release()
999 999

  
1000 1000
                    # Template Matching
1001 1001
                    tmRes = cv2.matchTemplate(roiItem, symGray, cv2.TM_CCOEFF_NORMED)
......
1191 1191

  
1192 1192
            contour_count = len(symbol_contours)
1193 1193
            for i in range(1, contour_count):
1194
                # contour size
1194 1195
                symbol_area = cv2.contourArea(symbol_contours[i])
1196
                # moments mass center
1197
                symbol_moments = cv2.moments(symbol_contours[i])
1198
                symbol_x = int(symbol_moments['m10'] / (symbol_moments['m00'] + 1e-5))
1199
                symbol_y = int(symbol_moments['m01'] / (symbol_moments['m00'] + 1e-5))
1200
                rect_x, rect_y, rect_w, rect_h = cv2.boundingRect(symbol_contours[i])
1201
                symbol_x = symbol_x - rect_x
1202
                symbol_y = symbol_y - rect_y
1203
                # percent x, y
1204
                percent_x = symbol_x / rect_w
1205
                percent_y = symbol_y / rect_h
1195 1206

  
1196 1207
                for contour in area.contours:
1197 1208
                    area_area = cv2.contourArea(contour)
......
1200 1211
                        I2 = cv2.matchShapes(symbol_contours[i], contour, 2, 0)
1201 1212
                        I3 = cv2.matchShapes(symbol_contours[i], contour, 3, 0)
1202 1213
                        if I1 < 1 and I2 < 1 and I3 < 0.1:
1203
                            # need shape check
1204

  
1205
                            rect = cv2.boundingRect(contour)
1206
                            results.append([1 - I3, [rect[0], rect[1]]])
1214
                            rect_x2, rect_y2, rect_w2, rect_h2 = cv2.boundingRect(contour)
1215
                            if rect_w * 1.2 >= rect_w2 >= rect_w * 0.8 and rect_h * 1.2 >= rect_h2 >= rect_h * 0.8:
1216
                                # moments mass center
1217
                                moments = cv2.moments(contour)
1218
                                x = int(moments['m10'] / (moments['m00'] + 1e-5))
1219
                                y = int(moments['m01'] / (moments['m00'] + 1e-5))
1220

  
1221
                                x = x - rect_x2
1222
                                y = y - rect_y2
1223
                                percent_x2 = x / rect_w2
1224
                                percent_y2 = y / rect_h2
1225

  
1226
                                value_x = abs(percent_x - percent_x2)
1227
                                value_y = abs(percent_y - percent_y2)
1228

  
1229
                                results.append([1 - (value_x + value_y), [rect_x2, rect_y2]])
1207 1230
                break
1208 1231
        except Exception as ex:
1209 1232
            message = 'error occurred({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename,

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)