easyidp.visualize.draw_polygon_on_img#
- easyidp.visualize.draw_polygon_on_img(img_name, img_path, poly_coord, corrected_poly_coord=None, title=None, save_as=None, show=False, color='red', alpha=0.5, dpi=72)#
Plot one polygon on given image.
- 参数:
img_name (str) – the image file name.
img_path (str) – the file path of image
poly_coord (np.ndarray) – the 2D polygon pixel coordinate on the image
corrected_poly_coord (np.ndarray, optional) – the corrected 2D polygon pixel coordiante on the image (if have), by default None
title (str, optional) – The image title displayed on the top, by default None ->
Projection on [img_name]
save_as (str, optional) – file path to save the output figure, by default None
show (bool, optional) – whether display (in jupyter notebook) or popup (in command line) the figure, by default False
color (str, optional) – the polygon line color, by default ‘red’
alpha (float, optional) – the polygon transparency, by default 0.5
dpi (int, optional) – the dpi of produced figure, by default 72
示例
Data prepare
>>> import easyidp as idp >>> p4d = idp.Pix4D( ... test_data.pix4d.lotus_folder, ... raw_img_folder=test_data.pix4d.lotus_photos, ... param_folder=test_data.pix4d.lotus_param ... ) >>> plot = np.array([ # N1E1 plot geo coordinate ... [ 368020.2974959 , 3955511.61264302, 97.56272272], ... [ 368022.24288365, 3955512.02973983, 97.56272272], ... [ 368022.65361232, 3955510.07798313, 97.56272272], ... [ 368020.69867274, 3955509.66725421, 97.56272272], ... [ 368020.2974959 , 3955511.61264302, 97.56272272] ... ])
Then do backward projection, find the previous ROI positions on the raw images.
>>> out_dict = p4d.back2raw_crs(plot, distort_correct=True) >>> out_dict["DJI_0177.JPG"] array([[ 137.10982937, 2359.55887614], [ 133.56116243, 2107.13954299], [ 384.767746 , 2097.05639105], [ 388.10993307, 2350.41225998], [ 137.10982937, 2359.55887614]])
The using this function to check one polygon on raw images
>>> img_name = "DJI_0198.JPG" >>> photo = p4d.photos[img_name] >>> idp.visualize.draw_polygon_on_img( ... img_name, photo.path, out_dict[img_name], ... save_as="p4d_back2raw_single_view.png")
It will get the following figure:
Add an corrected polygon (here manual shifting 10 pixels just as example), and change the color and alpha info:
>>> corrected_poly = out_dict[img_name] + np.array([10,10]) >>> idp.visualize.draw_polygon_on_img( ... img_name, photo.path, out_dict[img_name], corrected_poly, ... save_as="p4d_back2raw_single_view2.png", ... color='blue', alpha=0.3)
It will get the following figure: