A Tool: Zoom in/out and pan image with imshow and resize

I think lots of users have the problem about zooming in/out and pan images through opencv window.

Therefore, I have created a c++ class to finish this job.

With your mouse wheel and some parameter setting, you can easily view images.

Here are visual effect:

Total version of this simple class

key part of the code:

void COpenCVWindowExt::RefreshImage ()
{
	if (m_matSrc.empty ())
		return;
	Mat matResize;
	Size size (int (m_dNewScale * m_matSrc.cols), int (m_dNewScale * m_matSrc.rows));
	resize (m_matSrc, matResize, size);
	int iW = int (m_matSrc.cols * m_dInitialScale), iH = int (m_matSrc.rows * m_dInitialScale);

	Rect rectShow (Point (m_iHorzScrollBarPos, m_iVertScrollBarPos), Size (iW, iH));
	imshow (m_strWindowName, matResize (rectShow));
}
1 Like

Nice, from memory if you compile with QT you get this functionality aswell. That said not everyone wants to build against QT. If this is useful for people have you thought about adding it to OpenCV?

This is nothing about QT.
If you build this project (Win32 console application), you then can get this functionality.

About adding to OpenCV, I am thinking of it, but opencv can not create a vertical scroll bar, which means we can not use bars to see the scale status.

don’t bother. there are plans to completely redo the highgui module using accelerated graphics (OpenGL I think) so it’s independent of Qt (huge and legally troublesome) or system-specific toolkits.

1 Like