Search code examples
image-processingregionhalcon

How to rotate a region with an image


I want to rotate an image with a specific region. For example, if I rotate the image of 30 degrees, I want the regions to follow it.

I've tried the rotate_image function, and it does the job for the image, but not for the region.


Solution

  • By defining homogeneous matrices, you can use them on different object types:

    read_image (Image, 'fabrik') 
    gen_rectangle1 (Rectangle, 30, 20, 100, 200)
    
    hom_mat2d_identity (HomMat2DIdentity) 
    hom_mat2d_rotate (HomMat2DIdentity, 0.1, 0, 0, HomMat2DRotate)
    
    affine_trans_image (Image, ImageAffineTrans, HomMat2DRotate, 'constant', 'false') 
    affine_trans_region (Rectangle, RegionAffineTrans, HomMat2DRotate, 'nearest_neighbor')