@@ -591,3 +591,77 @@ def debug_image_quad_fit(self, image_debug):
591
591
cv2 .imwrite ('data/forcindy/0_quad.png' , im_orig )
592
592
593
593
print ("foo" )
594
+
595
+ from branchpointdetection import BranchPointDetection
596
+
597
+ # Compute all the branch points/approximate lines for branches
598
+ bp = BranchPointDetection ("data/forcindy/" , "0" )
599
+
600
+ # Read in/compute the additional images we need for debugging
601
+ # Original image, convert to canny edge
602
+ # Mask image
603
+ # Depth image
604
+ im_orig = cv2 .imread ('data/forcindy/0.png' )
605
+ im_depth = cv2 .imread ('data/forcindy/0_depth.png' )
606
+ im_mask_color = cv2 .imread ('data/forcindy/0_trunk_0.png' )
607
+ im_mask = cv2 .cvtColor (im_mask_color , cv2 .COLOR_BGR2GRAY )
608
+ im_gray = cv2 .cvtColor (im_orig , cv2 .COLOR_BGR2GRAY )
609
+ im_edge = cv2 .Canny (im_gray , 50 , 150 , apertureSize = 3 )
610
+ im_depth_color = cv2 .cvtColor (im_depth , cv2 .COLOR_BGR2RGB )
611
+ im_covert_back = cv2 .cvtColor (im_edge , cv2 .COLOR_GRAY2RGB )
612
+
613
+ # Write out edge image
614
+ cv2 .imwrite ('data/forcindy/0_edges.png' , im_edge )
615
+
616
+ # For the vertical leader...
617
+ trunk_pts = bp .trunks [0 ]["stats" ]
618
+ # Fit a quad to the trunk
619
+ quad = BezierCyl2D (trunk_pts ['lower_left' ], trunk_pts ['upper_right' ], 0.5 * trunk_pts ['width' ])
620
+
621
+ # Current parameters for the vertical leader
622
+ step_size_to_use = int (quad .radius_2d * 1.5 ) # Go along the edge at 1.5 * the estimated radius
623
+ perc_width_to_use = 0.3 # How "fat" to make the edge rectangles
624
+ perc_width_to_use_mask = 1.4 # How "fat" a rectangle to cover the mask
625
+
626
+ # Debugging image - draw the interior rects
627
+ quad .draw_interior_rects (im_mask_color , step_size = step_size_to_use , perc_width = perc_width_to_use_mask )
628
+ cv2 .imwrite ('data/forcindy/0_mask.png' , im_mask_color )
629
+
630
+ # For debugging images
631
+ fig , axs = plt .subplots (2 , 2 )
632
+ axs [0 , 0 ].imshow (im_orig )
633
+ axs [0 , 1 ].imshow (im_mask_color )
634
+ plt .tight_layout ()
635
+
636
+ # Iteratively move the quad to the center of the mask
637
+ for i in range (0 , 5 ):
638
+ res = quad .adjust_quad_by_mask (im_mask ,
639
+ step_size = step_size_to_use , perc_width = perc_width_to_use_mask ,
640
+ axs = axs [1 , 0 ])
641
+ print (f"Res { res } " )
642
+
643
+ # Draw the original, the edges, and the depth mask with the fitted quad
644
+ quad .draw_bezier (im_orig )
645
+ quad .draw_boundary (im_orig , 10 )
646
+ quad .draw_bezier (im_covert_back )
647
+
648
+ quad .draw_edge_rects (im_orig , step_size = step_size_to_use , perc_width = perc_width_to_use )
649
+ quad .draw_edge_rects (im_covert_back , step_size = step_size_to_use , perc_width = perc_width_to_use )
650
+ #quad.draw_edge_rects_markers(im_edge, step_size=step_size_to_use, perc_width=perc_width_to_use)
651
+ quad .draw_interior_rects (im_depth_color , step_size = step_size_to_use , perc_width = perc_width_to_use )
652
+
653
+ im_both = np .hstack ([im_orig , im_covert_back , im_depth_color ])
654
+ cv2 .imshow ("Original and edge and depth" , im_both )
655
+ cv2 .imwrite ('data/forcindy/0_rects.png' , im_both )
656
+
657
+ # Now do the hough transform - first draw the hough transform edges
658
+ for i in range (0 , 5 ):
659
+ ret = quad .adjust_quad_by_hough_edges (im_edge , step_size = step_size_to_use , perc_width = perc_width_to_use , axs = axs [1 , 1 ])
660
+ print (f"Res Hough { ret } " )
661
+
662
+ im_orig = cv2 .imread ('data/forcindy/0.png' )
663
+ quad .draw_bezier (im_orig )
664
+ quad .draw_boundary (im_orig , 10 )
665
+ cv2 .imwrite ('data/forcindy/0_quad.png' , im_orig )
666
+
667
+ print ("foo" )
0 commit comments