windows OpenCV - 如何启用滚动到带有图像的窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4884959/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV - How to enable scrolling to windows with images?
提问by Rella
So currently I open images created with openCV with something like
所以目前我打开用 openCV 创建的图像
cvNamedWindow( "Original Image", CV_WINDOW_AUTOSIZE );
cvShowImage( "Original Image", original );
but my images are quite large and go off the screen like shown here
但我的图像非常大并且像这里显示的那样从屏幕上消失
I want windows to be resizable or at least the size of the users screen but with scrolling.
我希望窗口可以调整大小或至少是用户屏幕的大小但可以滚动。
How to do such thing?
这样的事情怎么办?
回答by mpenkov
EDIT
编辑
Short answer: you can't "enable" it, you have to implement it.
简短的回答:你不能“启用”它,你必须实现它。
OpenCV does have trackbars -- have a look at the documentation, in particular the cvCreateTrackbar
function. However, even if you use them, you still have to write the code behind it (for determining the new ROI and determining what to actually show).
OpenCV 确实有轨迹栏——查看文档,特别是cvCreateTrackbar
功能。但是,即使您使用它们,您仍然必须编写其背后的代码(用于确定新的 ROI 并确定实际显示的内容)。
If this sounds a bit too daunting, then you can wrap the displayed image using some GUI framework. Here is an examplethat uses OpenCV with wxWidgets. Of course, you can use any other GUI framework (for example, Qt).
如果这听起来有点令人生畏,那么您可以使用一些 GUI 框架来包装显示的图像。这是一个使用带有 wxWidgets 的 OpenCV的示例。当然,您可以使用任何其他 GUI 框架(例如 Qt)。
回答by Guestyguest
This might help for one step: Just use CV_WINDOW_NORMAL
instead of CV_WINDOW_AUTOSIZE
.
这可能有助于第一步:只需使用CV_WINDOW_NORMAL
而不是CV_WINDOW_AUTOSIZE
.
cvNamedWindow(yourWindowName, CV_WINDOW_NORMAL);
cvShowImage("Original Image", original);
回答by tsmgeo
A simple way to scroll large image is by usage of trackbar and a Rectangular for snipping.
滚动大图像的一种简单方法是使用轨迹栏和 Rectangular 进行剪切。
.
.
.
namedWindow("winImage",WINDOW_AUTOSIZE);
namedWindow("controlWin",WINDOW_AUTOSIZE);
int winH=300;
int winW=600;
if(winH>=largeImage.rows)winH=largeImage.rows-1;
if(winW>=largeImage.cols)winW=largeImage.cols-1;
int scrolHight=0;
int scrolWidth=0;
cvCreateTrackbar("Hscroll", "controlWin", &scrolHight, (largeImage.rows -winH));
cvCreateTrackbar("Wscroll", "controlWin", &scrolWidth, (largeImage.cols -winW));
while(waitKey(0)!='q'){
Mat winImage= largeImage( Rect(scrolWidth,scrolHight,winW,winH) );
imshow("winImage",winImage);
}//while
.
.
回答by Cheers and hth. - Alf
As far as I know (but I've only recently started looking at OpenCV) you need to build the OpenCV library with the Qt GUI library as GUI backend.
据我所知(但我最近才开始研究 OpenCV),您需要使用 Qt GUI 库作为 GUI 后端来构建 OpenCV 库。
Then you get all the cute functions.
然后你会得到所有可爱的功能。
Well, OK, there's not very much, but the little that is there is documented as Qt only.
好吧,没有太多,但是只有 Qt 记录了其中的一小部分。
EDIT: PS, since possibly other answer might sow confusion, I'm nottalking about using Qt to implement such functionality yourself. I'm talking about the functionality available in OpenCV's HighGUI module.
编辑:PS,因为其他答案可能会造成混乱,我不是在谈论使用 Qt 自己实现此类功能。我说的是 OpenCV 的 HighGUI 模块中可用的功能。
Cheers & hth.,
干杯 & hth.,
回答by gameon67
The best thing that I can do with pure opencv is by modifying the opencv trackbarmethod. I'm using ROI to update the display image according to the slider value. The weaknessof this method is, opencv trackbar is displayed horizontally not vertically like the normal scrollbar, so in this case it is up to you whether you want to rotate your image horizontally or not.
我可以用纯 opencv 做的最好的事情是修改opencv trackbar方法。我正在使用 ROI 根据滑块值更新显示图像。这种方法的弱点是,opencv trackbar 是水平显示的,而不是像普通滚动条那样垂直显示,因此在这种情况下,是否要水平旋转图像取决于您。
int slider_max, slider, displayHeight;
int displayWidth = 1900;
Mat src1; // original big image
Mat dst;
cv::Rect roi;
static void on_trackbar(int, void*)
{
roi = cv::Rect(slider, 0, displayWidth, displayHeight); //Update ROI for display
dst = src1(roi);
imshow("Result", dst);
}
int main(void)
{
src1 = imread("BigImg.jpg"); // your big image
cv::rotate(src1, src1, cv::ROTATE_90_CLOCKWISE); //I rotate my image because opencv trackbar is displayed horizontally
cv::resize(src1, src1, cv::Size(src1.cols/2, src1.rows/2)); // resize the image if it's too big to display in 1 window
if (src1.empty()) { cout << "Error loading src1 \n"; return -1; }
slider_max = src1.cols - displayWidth;
slider = 0;
displayHeight = src1.rows;
namedWindow("Result", WINDOW_AUTOSIZE); // Create Window
char TrackbarName[50];
sprintf(TrackbarName, "Pixel Pos");
createTrackbar(TrackbarName, "Result", &slider, slider_max, on_trackbar);
on_trackbar(slider, 0);
waitKey(0);
return 0;
}
For changing the trackbar's orientation then you will need to use Qt or other GUI How to change the position of the trackbar in OpenCV applications?
要更改轨迹栏的方向,则需要使用 Qt 或其他 GUI如何在 OpenCV 应用程序中更改轨迹栏的位置?