Image in any size show in the center of the screen

OpenCV, C++:

I present images by the command cv::imshow.
I have images in different size and I want for each image that it will present it in the center of the screen.
I tried to do this with the command cv::moveWindow but it does not display any image in any size in the center of the screen.

Thanks

show (code), what you’ve tried, please

I am doing:

cv::namedWindow(“Image”);
cv::moveWindow(“Image”, 300, 140);
cv::imshow(“Image”, image);

for images that are about 1200x628 in size it displays in the center of the screen, but for images that are about 600x500 in size it displays on the left size of the screen.
I want command that always display the image in the center of the screen regardless of the size of the image.

Thanks

so, it’s more of a maths problem ?
you probably have to make the offset adjust to the image size,
something like:

int win_x = screen_width/2 - image.cols/2;
int win_y = screen_height/2 - image.rows/2 - 30; // the bar
cv::moveWindow(“Image”, win_x, win_y);

should do the trick

1 Like

It worked. Thank you very much!