ppf_load_match.py 938 B

1234567891011121314151617181920212223242526272829303132
  1. import cv2 as cv
  2. N = 2
  3. modelname = "parasaurolophus_6700"
  4. scenename = "rs1_normals"
  5. detector = cv.ppf_match_3d_PPF3DDetector(0.025, 0.05)
  6. print('Loading model...')
  7. pc = cv.ppf_match_3d.loadPLYSimple("data/%s.ply" % modelname, 1)
  8. print('Training...')
  9. detector.trainModel(pc)
  10. print('Loading scene...')
  11. pcTest = cv.ppf_match_3d.loadPLYSimple("data/%s.ply" % scenename, 1)
  12. print('Matching...')
  13. results = detector.match(pcTest, 1.0/40.0, 0.05)
  14. print('Performing ICP...')
  15. icp = cv.ppf_match_3d_ICP(100)
  16. _, results = icp.registerModelToScene(pc, pcTest, results[:N])
  17. print("Poses: ")
  18. for i, result in enumerate(results):
  19. #result.printPose()
  20. print("\n-- Pose to Model Index %d: NumVotes = %d, Residual = %f\n%s\n" % (result.modelIndex, result.numVotes, result.residual, result.pose))
  21. if i == 0:
  22. pct = cv.ppf_match_3d.transformPCPose(pc, result.pose)
  23. cv.ppf_match_3d.writePLY(pct, "%sPCTrans.ply" % modelname)