简体   繁体   中英

OpenCV cv::imshow() does not work but cvShowImage() does

I'm having an issue that I've never had with OpenCV before. When I use cv::imshow() the image is shown perfectly, but there are weird ascii characters along the top bar instead of the window name and every few seconds a new window appears with a different name and the old freezes on whatever frame it was currently on. I can exit out of the windows that are frozen but more appear instantly after with different names. I have used OpenCV before and imshow() has always worked for me. Here's my code:

#include "stdafx.h"
#include "opencv2/opencv.hpp"

using namespace cv;

int main()
{
    VideoCapture cap(0);
    Mat frame;
    namedWindow("Sample Program", CV_WINDOW_AUTOSIZE);

    while (true)
    {
        cap >> frame;

        imshow("Sample Program", frame);

        if(waitKey(30) >= 0) break;
    }

    return 0;
}

If I replace imshow() with

cvShowImage("Sample Program", cvCloneImage(&(IplImage)frame));

It works perfectly. I just want to know if theres a library issue or something that is causing this issue I'm using OpenCV 2.4.9 in Visual Studio Ultimate 2012

using namespace std;
using namespace cv;

With that cv it works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM