Ask Your Question
0

image height and width

asked 2014-09-20 23:13:11 -0600

Icetray gravatar image

Hi Guys,

Is it possible to get the height and width of an image? I tried using image.get(3) and image.get(4) as I do with video captures but it doesn't seem to work with still images.

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-09-21 00:04:49 -0600

rwong gravatar image

Assuming this is c++

cv::Size sz = image.size();
int imageWidth = sz.width;
int imageHeight = sz.height;

Note: if the image has higher dimension than 2D (i.e. representing time-lapse or a stack of images), this may throw an exception.

edit flag offensive delete link more

Comments

Thank you!

Is there a reason why I can't use a pointer for these statements? I get an error message saying that the expression must have a class type (*image is underlined). I'm planning to use this in a function.

Size sz = *image.size(); int imageWidth = sz.width; int imageHeight = sz.height;

Icetray gravatar imageIcetray ( 2014-09-21 00:19:23 -0600 )edit

@Icetray: (*image).size(); // you need proper braces

but do not keep or pass around pointers to cv::Mat. those are already refcounted smartpointers, and you will inevitably wreck the internal refcounts this way.

berak gravatar imageberak ( 2014-09-21 00:54:24 -0600 )edit

Thanks berak! This works perfectly!

Icetray gravatar imageIcetray ( 2014-09-21 00:57:50 -0600 )edit

Hi berak,

can you explain what you mean by "but do not keep or pass around pointers to cv::Mat. those are already refcounted smartpointers, and you will inevitably wreck the internal refcounts this way."?

I thought it was more efficient to pass your images as pointers?

Icetray gravatar imageIcetray ( 2014-09-21 00:59:19 -0600 )edit

a Mat header has only 56 bytes. don't be afraid to copy that. using pointers is far too dangerous, as you're playing against the rules. please lookup, how refcounting works.

berak gravatar imageberak ( 2014-09-21 01:05:15 -0600 )edit

Question Tools

Stats

Asked: 2014-09-20 23:13:11 -0600

Seen: 12,671 times

Last updated: Sep 21 '14