Search code examples
coordinatesregionhalcon

Halcon - get area of region in world coordinates


I have following code:

image_points_to_world_plane (CamParam, Pose, intersection_points_row, intersection_points_col, 'mm', X1, Y1)
distance_pp (X1[2], Y1[2], X1[3], Y1[3], Measure1)

this code retunrs the values in mm.

now the code goes on as shown below, and I would need the area of the Regions1 in mm². Instead i get them in pixel..

access_channel(Image, ImageMono, 1)

threshold(ImageMono, Region, 0, 100)
fill_up(Region, RegionFillUp)

reduce_domain(ImageMono, RegionFillUp, ImageReduced)

threshold (ImageReduced, Regions1, 230, 255)
connection (Regions1, Connection)
select_shape(Connection, Labels, 'area', 'and', 2000, 99999)
area_center(Labels, AreaLabels, RowLabels, ColumnLabels)

AreaLabels is in px² and i would need it in mm². but couldnt find anything like region_to_world_plane... how can this be done?


Solution

  • Try looking at the operator "image_to_world_plane". It will transform the image so that the pixel size is in metric units (or whatever you prefer). It will also warp the image so that it looks as if the picture was taken directly from overhead. Then any area calculations you perform on this transformed image will be in the units you specified (mm, m, etc).