CVB cropping problem

Hey,

I know that the width and height of the sensor cannot be changed. However, When I try to change the width and height value I have to also change the horizontal and vertical offset. For example, for 640x480 image, I must set the horizontal and vertical offset that is 672*392 respectively to get center image.

I facing this problem where I don’t want to crop the image, instead I am looking for an option to resize the image to 640x480 without cropping. However, I am unable to solve this issue.

Any feedback would be highly appreciated I am having nano c1930 camera.

Regards,
Affi

What you are looking for is the Map() method of the :cvb: image object

map()

def map ( self ,
source_rect ,
target_size = source_rect.size
)

Creates a mapped image of the region of that image scaled to the size.

As this is simply a view to another image, no interpolation is done,when the mapped pixels are accessed. Smaller sizes lead to pixel skipping, while larger sizes lead to replicated pixels.

Parameters

source_rect : cvb.Rect Region to create the map from.

target_size : cvb.Size2D Target size of the mapped image.

Returns

cvb.Image The mapped image.

That is one option - and by far the fastest! - to get to your 640x480 image. Keep in mind, however, what the description cited by @rtp_derahs hinted at with the pixel skipping: The map function (based on the C-API function CreateImageMap will only drop pixels when downscaling (or insert duplicates when upscaling). This is by far the fasted approach you can choose - but it unfortunately also won’t yield pretty images.

If you value quality higher than speed, have a look at the resize functions (ResizeImage from the CVFoundation.dll if you are using the C-API, cvb.foundation.resize in CVBpy etc…). This one will let you select an interpolation method (linear is usually a good trade-off between quality and speed) and yield pictures that looke nicer and have fewer rescaling artifacts than what map yields. It is part of the :cvb: Foundation Package, so it’s unfortunately not covered by the CameraSuite/ImageManager license.

If the latter is a serious limitation, have a look at CreateMatrixTransformedImage (C-API). This - combined with a scaling matrix - will have the same effect (applying a linear interpolation as it goes). In CVBpy this maps to the matrix_transform member function of the image object.

By the way: I see that CVBpy might have been an assumption on @rtp_derahs 's side - not sure what you are actually using. If you let us know the programm language you’re using it’s easier for us to give helpful pointers :slight_smile:

1 Like

Hey @illusive and @rtp_derahs,

Thank you so much for the insight.

I have looked here about the Image resolution, which clearly stated that:

If you change a setting in the camera which changes the resolution or pixel size of the image, you need to update the image object by using the IImageRect Interface.

Refer this section for more information.

I didn’t get it what exactly it means. What I am trying do is to change the image resolution from the GeniCam browser and then make that changes pragmatically using cvbpython via Nodeapp.

@illusive I am using python.

Regards,
Aftab

1 Like

Hi @aftab,

Please have a look at my answer to this post.
This should make clear, what your mentioned article is talking about :slightly_smiling_face:

By the way: The :cvb: GenICam Browser does all this for you!

Cheers,
Thomas

1 Like

Hey @rtp_derahs,

Your reply was faster than light :slight_smile: I have check the other post. This means I don’t need to set the horizontal and vertical offset if I use the code which you mentioned that is cvb.Size2D(…)?

I have to make another point that I am using fish-eye lens. I noticed that If I change the image resolution I have to set the offsets (horizontal and vertical) values also (played and tested with GeniCam Browser). This behavior confuses me. Because If the offsets are not correct set I will not get the correct image.

Thank you so much for your time and feedback.

1 Like

The offset still must be set manually.
The ImageRect provides the “offset” property for that:

Have a look at the programming reference

1 Like