Home

Add

Edit

Without Linenumbers

Code in Textfield

umrechnen von pixelhaufen in linien

  1. '##############################################################################################################
    
  2. '  V O R C O - Visual Object Recognition
    
  3. '##############################################################################################################
    
  4. 
    
  5. 
    
  6. 
    
  7. '##############################################################################################################
    
  8. Dim Shared VORCO_Aly_Geometry3_ImgKD        As Any Ptr
    
  9. Dim Shared VORCO_Aly_Geometry3_ImgKP        As Uinteger Ptr
    
  10. 
    
  11. 
    
  12. 
    
  13. '##############################################################################################################
    
  14. Sub VORCO_Aly_Geometry3_Init(V_Filter_Deep As Uinteger = 2)
    
  15. End Sub
    
  16. 
    
  17. 
    
  18. 
    
  19. '##############################################################################################################
    
  20. Sub VORCO_Aly_Geometry3_Term()
    
  21. End Sub
    
  22. 
    
  23. 
    
  24. 
    
  25. '##############################################################################################################
    
  26. Function VORCO_Aly_Geometry3_Do(V_Object As VORCO_PlaneObj_Type Ptr, V_LineBreakDis As Uinteger = 5) As Integer
    
  27. If V_Object = 0 Then Return 0
    
  28. With *V_Object
    
  29.     Dim TPtrGeom As VORCO_PlaneGeom_Type Ptr = .V_Geom_F
    
  30.     Dim TPtrGeomT As VORCO_PlaneGeom_Type Ptr
    
  31.     If TPtrGeom = 0 Then Return 0
    
  32.     Dim TPGX As Uinteger
    
  33.     Dim TPRX As Uinteger
    
  34.     Dim TPRY As Uinteger
    
  35.     Dim TPRX1 As Uinteger
    
  36.     Dim TPRY1 As Uinteger
    
  37.     Dim TPRV As Integer
    
  38.     Dim TPRC As Uinteger
    
  39.     Dim TRate As Uinteger = V_LineBreakDis
    
  40.     Dim TSRateX(.V_PointCount) As Uinteger
    
  41.     Dim TSRateY(.V_PointCount) As Uinteger
    
  42.     Dim TSRateV(.V_PointCount) As Uinteger
    
  43.     Dim TSRateZ As Uinteger
    
  44.     Dim TSRate As Uinteger = 3
    
  45.     Dim TCol As Ushort
    
  46.     Dim TColT As Uinteger
    
  47.     Dim TX1 As Uinteger = -1
    
  48.     Dim TX2 As Uinteger
    
  49.     Dim TY1 As Uinteger = -1
    
  50.     Dim TY2 As Uinteger
    
  51.     Dim TZ As Uinteger
    
  52.     TPGX = 0
    
  53.     TCol = 0
    
  54.     Do Until TPtrGeom = 0
    
  55.         TPtrGeomT = TPtrGeom
    
  56.         TPRC = 0
    
  57.         TPRX = 0
    
  58.         TPRY = 0
    
  59.         Do Until TPtrGeomT = 0
    
  60.             If TPtrGeomT->V_Next = 0 Then Exit Do
    
  61.             TPRC += 1
    
  62.             TPRX += (TPtrGeomT->V_X - TPtrGeomT->V_Next->V_X)
    
  63.             TPRY += (TPtrGeomT->V_Y - TPtrGeomT->V_Next->V_Y)
    
  64.             If TPRC = TRate Then Exit Do
    
  65.             TPtrGeomT = TPtrGeomT->V_Next
    
  66.         Loop
    
  67.         TPRX = Abs(TPRX)
    
  68.         TPRY = Abs(TPRY)
    
  69.         TSRateZ += 1
    
  70.         TSRateX(TSRateZ) = TPRX
    
  71.         TSRateY(TSRateZ) = TPRY
    
  72.         If TPtrGeom->V_Next = 0 Then Exit Do
    
  73.         TPtrGeom = TPtrGeom->V_Next
    
  74.     Loop
    
  75.     TCol = 0
    
  76.     For TPGX = 1 To .V_PointCount - TSRate
    
  77.         TPRX = 0
    
  78.         TPRY = 0
    
  79.         TPRX1 = 0
    
  80.         TPRY1 = 0
    
  81.         For TPRC = TPGX To TPGX + TSRate
    
  82.             TPRX += TSRateX(TPRC)
    
  83.             TPRY += TSRateY(TPRC)
    
  84.         Next
    
  85.         For TPRC = TPGX + TSRate To TPGX + TSRate * 2
    
  86.             TPRX1 += TSRateX(TPRC)
    
  87.             TPRY1 += TSRateY(TPRC)
    
  88.         Next
    
  89.         TPRX = TPRX / TSRate
    
  90.         TPRY = TPRY / TSRate
    
  91.         TPRX1 = TPRX1 / TSRate
    
  92.         TPRY1 = TPRY1 / TSRate
    
  93.         TPRX = Abs(TPRX - TPRX1)
    
  94.         TPRY = Abs(TPRY - TPRY1)
    
  95.         TPRV = ((TPRY + TPRX) * 40)
    
  96.         TPRV -= 40
    
  97.         TPRV /= 4
    
  98.         If TPRV < 0 Then TPRV = 0
    
  99.         TSRateV(TPGX) = TPRV
    
  100.     Next
    
  101.     For TPGX = 1 To .V_PointCount
    
  102.         If TSRateV(TPGX) > 0 Then
    
  103.             For TPRX = TPGX + 1 To .V_PointCount
    
  104.                 If TSRateV(TPRX) = 0 Then
    
  105.                     For TPRY = TPGX To TPRX - 1
    
  106.                         TSRateV(TPRY) = 0
    
  107.                     Next
    
  108.                     TPRY = TPRX
    
  109.                     If TPRY < 1 Then TPRY = 1
    
  110.                     If TPRY > .V_PointCount Then TPRY = .V_PointCount
    
  111.                     TSRateV(TPRY) = 10
    
  112.                     TPGX = TPRX
    
  113.                     Exit For
    
  114.                 End If
    
  115.             Next
    
  116.         End If
    
  117.     Next
    
  118.     TPGX = 0
    
  119.     TCol = 0
    
  120.     TPtrGeom = .V_Geom_F
    
  121.     TPtrGeomT = TPtrGeom
    
  122.     Dim TGOPtr As VORCO_PlaneGeomObj_Type Ptr
    
  123.     Do Until TPtrGeom = 0
    
  124.         TPGX += 1
    
  125.         If TSRateV(TPGX) > 0 Then
    
  126.             If TCol = 0 Then TCol = 255 Else TCol = 0
    
  127.             If TGOPtr <> 0 Then
    
  128.                 TGOPtr->V_Next = Callocate(Sizeof(VORCO_PlaneGeomObj_Type))
    
  129.                 TGOPtr->V_Next->V_Prev = TGOPtr
    
  130.                 TGOPtr = TGOPtr->V_Next
    
  131.             Else
    
  132.                 TGOPtr = Callocate(Sizeof(VORCO_PlaneGeomObj_Type))
    
  133.                 .V_GeomObj_F = TGOPtr
    
  134.             End If
    
  135.             With *TGOPtr
    
  136.                 .V_Type     = VORCO_PGObj_Line
    
  137.                 .V_X1       = TPtrGeomT->V_X
    
  138.                 .V_Y1       = TPtrGeomT->V_Y
    
  139.                 .V_X2       = TPtrGeom->V_X
    
  140.                 .V_Y2       = TPtrGeom->V_Y
    
  141.             End With
    
  142.             If TX1 > TPtrGeomT->V_X Then TX1 = TPtrGeomT->V_X
    
  143.             If TX2 < TPtrGeomT->V_X Then TX2 = TPtrGeomT->V_X
    
  144.             If TY1 > TPtrGeomT->V_Y Then TY1 = TPtrGeomT->V_Y
    
  145.             If TY2 < TPtrGeomT->V_Y Then TY2 = TPtrGeomT->V_Y
    
  146.             If TX1 > TPtrGeom->V_X Then TX1 = TPtrGeom->V_X
    
  147.             If TX2 < TPtrGeom->V_X Then TX2 = TPtrGeom->V_X
    
  148.             If TY1 > TPtrGeom->V_Y Then TY1 = TPtrGeom->V_Y
    
  149.             If TY2 < TPtrGeom->V_Y Then TY2 = TPtrGeom->V_Y
    
  150.             TZ += 1
    
  151.             Line (1000 + TPtrGeomT->V_X, 260 + TPtrGeomT->V_Y)-(1000 + TPtrGeom->V_X, 260 + TPtrGeom->V_Y), Rgb(255 - TCol, TCol, TCol)
    
  152.             TPtrGeomT = TPtrGeom
    
  153.         End If
    
  154.         TPtrGeom = TPtrGeom->V_Next
    
  155.     Loop
    
  156.     .V_Geom_Count   = TZ
    
  157.     .V_Geom_Left    = TX1
    
  158.     .V_Geom_Top     = TY1
    
  159.     .V_Geom_Width   = TX2 - TX1 + 1
    
  160.     .V_Geom_Height  = TY2 - TY1 + 1
    
  161. End With
    
  162. Return 0
    
  163. End Function
    



Umrechnen von linien in circle

  1. '##############################################################################################################
    
  2. '  V O R C O - Visual Object Recognition
    
  3. '##############################################################################################################
    
  4. 
    
  5. 
    
  6. 
    
  7. '##############################################################################################################
    
  8. Function VORCO_Aly_Geometry_Translate1_Do(V_Object As VORCO_PlaneObj_Type Ptr) As Integer
    
  9. If V_Object = 0 Then Return 0
    
  10. With *V_Object
    
  11.     Dim TPtrGeom As VORCO_PlaneGeom_Type Ptr = .V_Geom_F
    
  12.     If .V_PointCount >= 8 Then
    
  13.         Dim TCX As Uinteger = V_Object->V_IIPX + .V_Width / 2
    
  14.         Dim TCY As Uinteger = V_Object->V_IIPY + .V_Height / 2
    
  15.         Dim TCCD As Uinteger
    
  16.         Dim TCCSX As Uinteger
    
  17.         Dim TCCSY As Uinteger
    
  18.         Dim TCCX As Uinteger
    
  19.         Do Until TPtrGeom = 0
    
  20.             With *TPtrGeom
    
  21.                 TCCD = Sqr(Abs((TCX - .V_X)) ^ 2 + Abs((TCY - .V_Y)) ^ 2)
    
  22.                 TCCSY += Abs((V_Object->V_Height / 2) - TCCD)
    
  23.                 TCCSX += Abs((V_Object->V_Width / 2) - TCCD)
    
  24.                 TCCX += 1
    
  25.             End With
    
  26.             TPtrGeom = TPtrGeom->V_Next
    
  27.         Loop
    
  28.         TCCSX /= .V_PointCount
    
  29.         TCCSY /= .V_PointCount
    
  30.         TCCX = .V_PointCount / 30
    
  31.         If TCCX < 1 Then TCCX = 1
    
  32.         TCCSX = (100 / (.V_Width / 2) * TCCSX)
    
  33.         TCCSY = (100 / (.V_Height / 2) * TCCSY)
    
  34.         If (TCCSX <= TCCX) And (TCCSY <= TCCX) Then
    
  35.             If .V_GeomObj_L <> 0 Then
    
  36.                 .V_GeomObj_L->V_Next = Callocate(Sizeof(VORCO_PlaneGeomObj_Type))
    
  37.                 .V_GeomObj_L->V_Next->V_Prev = .V_GeomObj_L
    
  38.                 .V_GeomObj_L = .V_GeomObj_L->V_Next
    
  39.             Else
    
  40.                 .V_GeomObj_L = Callocate(Sizeof(VORCO_PlaneGeomObj_Type))
    
  41.                 .V_GeomObj_F = .V_GeomObj_L
    
  42.             End If
    
  43.             With *.V_GeomObj_L
    
  44.                 .V_Type     = VORCO_PGObj_Circle
    
  45.                 .V_X1 = TCX
    
  46.                 .V_Y1 = TCY
    
  47.                 If V_Object->V_Width > V_Object->V_Height Then
    
  48.                     .V_D1 = V_Object->V_Width / 2
    
  49.                     .V_D2 = V_Object->V_Height / V_Object->V_Width
    
  50.                 Else
    
  51.                     .V_D1 = V_Object->V_Width / 2
    
  52.                     .V_D2 = V_Object->V_Width / V_Object->V_Height
    
  53.                 End If
    
  54.             End With
    
  55.         End If
    
  56.     End If
    
  57. End With
    
  58. Return 0
    
  59. End Function
    



ein Paar Typen und Enums die Verwendung finden

  1. Enum VORCO_PlaneGeomObj_Enum
    
  2.     VORCO_PGObj_Unknown     = 0
    
  3.     VORCO_PGObj_Line        = 1
    
  4.     VORCO_PGObj_Circle      = 2
    
  5. End Enum
    
  6. 
    
  7. '--------------------------------------------------------------------------------------------------------------
    
  8. Type VORCO_PlaneGeomObj_Type
    
  9.     V_Next                  As VORCO_PlaneGeomObj_Type Ptr
    
  10.     V_Prev                  As VORCO_PlaneGeomObj_Type Ptr
    
  11.     
    
  12.     V_Type                  As VORCO_PlaneGeomObj_Enum
    
  13.     V_X1                    As Uinteger
    
  14.     V_Y1                    As Uinteger
    
  15.     V_X2                    As Uinteger
    
  16.     V_Y2                    As Uinteger
    
  17.     V_D1                    As Double
    
  18.     V_D2                    As Double
    
  19. End Type
    
  20. 
    
  21. '--------------------------------------------------------------------------------------------------------------
    
  22. Type VORCO_PlaneGeom_Type
    
  23.     V_Next                  As VORCO_PlaneGeom_Type Ptr
    
  24.     V_Prev                  As VORCO_PlaneGeom_Type Ptr
    
  25.     
    
  26.     V_X                     As Uinteger
    
  27.     V_Y                     As Uinteger
    
  28. End Type
    
  29. 
    
  30. '--------------------------------------------------------------------------------------------------------------
    
  31. Type VORCO_PlaneObj_Type
    
  32.     V_Next                  As VORCO_PlaneObj_Type Ptr
    
  33.     V_Prev                  As VORCO_PlaneObj_Type Ptr
    
  34.     
    
  35.     V_IIPX                  As Uinteger
    
  36.     V_IIPY                  As Uinteger
    
  37.     V_Width                 As Uinteger
    
  38.     V_Height                As Uinteger
    
  39.     V_Image                 As Any Ptr
    
  40.     V_PointCount            As Uinteger
    
  41.     
    
  42.     V_Geom_F                As VORCO_PlaneGeom_Type Ptr
    
  43.     V_Geom_Count            As Uinteger
    
  44.     V_Geom_Left             As Uinteger
    
  45.     V_Geom_Top              As Uinteger
    
  46.     V_Geom_Width            As Uinteger
    
  47.     V_Geom_Height           As Uinteger
    
  48.     
    
  49.     V_GeomObj_F             As VORCO_PlaneGeomObj_Type Ptr
    
  50.     V_GeomObj_L             As VORCO_PlaneGeomObj_Type Ptr
    
  51. End Type
    
  52. 
    
  53. '--------------------------------------------------------------------------------------------------------------
    
  54. Type VORCO_Obj_Type
    
  55.     V_Next                  As VORCO_Obj_Type Ptr
    
  56.     V_Prev                  As VORCO_Obj_Type Ptr
    
  57.     
    
  58.     V_OBJ_ID                As Uinteger
    
  59.     V_Geom_F                As VORCO_PlaneGeom_Type Ptr
    
  60.     V_Geom_FirstTrak        As VORCO_PlaneGeom_Type Ptr
    
  61. End Type
    


Aufruf und zeichnung. Die umrechnung erfolgt aus dem zuvor generiertem Rumrandungsalgo. Ähnlich diesem hier: blub.bas
  1.         TImgFielded = VORCO_Aly_Fielding1_Do(TItemC, TObjPlane, TImgNoiseFiltered, TImgEdged, TImgEdgedOpti, 50, 50)
    
  2. '...
    
  3.     TPtr = TObjPlane
    
  4. '...
    
  5.         VORCO_Aly_Geometry3_Do(TPtr)
    
  6.         VORCO_Aly_Geometry_Translate1_Do(TPtr)
    
  7.         Dim TPtrGeomObj As VORCO_PlaneGeomObj_Type Ptr = TPtr->V_GeomObj_F
    
  8.         TC = 0
    
  9.         Do Until TPtrGeomObj = 0
    
  10.             TC += 1
    
  11.             With *TPtrGeomObj
    
  12.                 Select Case .V_Type
    
  13.                     Case VORCO_PGObj_Unknown
    
  14.                         
    
  15.                     Case VORCO_PGObj_Line
    
  16.                         Line (10 + .V_X1, 10 + .V_Y1)-(10 + .V_X2, 10 + .V_Y2), &H00FF00
    
  17.                         
    
  18.                     Case VORCO_PGObj_Circle
    
  19.                         Circle (10 + .V_X1, 10 + .V_Y1), .V_D1, &H00FF00, , , .V_D2
    
  20.                         
    
  21.                 End Select
    
  22.             End With
    
  23.             TPtrGeomObj = TPtrGeomObj->V_Next
    
  24.         Loop