Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ imshow不起作用了_C++_Opencv_Image Processing - Fatal编程技术网

C++ imshow不起作用了

C++ imshow不起作用了,c++,opencv,image-processing,C++,Opencv,Image Processing,我使用for循环读取300帧并对其进行累加。我在内部发出imshow命令以连续打印帧,但在for循环处理期间不会打印帧,而是作为单个图像打印 这是我的密码: enter code here #include<iostream> #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include<stdlib.h> #include<stdio.h> us

我使用for循环读取300帧并对其进行累加。我在内部发出imshow命令以连续打印帧,但在for循环处理期间不会打印帧,而是作为单个图像打印

这是我的密码:

enter code here

#include<iostream>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include<stdlib.h>
#include<stdio.h>
using namespace cv;
using namespace std;
int main()
{
  char k;
  int learningframes=300;
  VideoCapture cap(0);
  if(cap.isOpened()==0)
  {
    cout<<"ERROR";
    return -1;
  }

  //while(1)
  //{
  Mat frame;
  cap>>frame;
  Mat frameaccF,frameacc,framethr32,framehsv,framethr;
  frameaccF=Mat::zeros(frame.size(),CV_32FC1);
  for(int i=0;i<=learningframes;i++)
  {
    cap>>frame;
    imshow("nn",frame); 
    cvtColor(frame,framehsv,CV_BGR2HSV);

    inRange(framehsv,Scalar(0,30,0),Scalar(50,150,255),framethr);

    framethr.convertTo(framethr,CV_32F);



    accumulate(framethr,frameaccF);
  }
  frameaccF=frameaccF/300;
  frameaccF.convertTo(frameaccF,CV_8U);
  imshow("frame",frame);
  imshow("frameacc",frameaccF);

    waitKey(0);
  //if(k=='q')
  //break;
  //}

  return 0;
  }
在此处输入代码
#包括
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括
#包括
使用名称空间cv;
使用名称空间std;
int main()
{
chark;
int learningframes=300;
视频捕获上限(0);
如果(cap.isOpened()==0)
{
沙发架;
Mat frameaccF、frameacc、framethr32、framehsv、framethr;
frameaccF=Mat::零(frame.size(),CV_32FC1);
对于(int i=0;i>frame;
imshow(“nn”,帧);
CVT颜色(框架、框架HSV、CV_BGR2HSV);
范围(framehsv,标量(0,30,0),标量(50150255),framethr);
框架转换器(框架,CV_32F);
累计(framethr、frameaccF);
}
frameaccF=frameaccF/300;
frameaccF.convertTo(frameaccF,CV_8U);
imshow(“框架”,框架);
imshow(“frameacc”,frameaccF);
等待键(0);
//如果(k=='q')
//中断;
//}
返回0;
}

您需要将
waiKey()放入for循环中

for(int i=0;i<=learningframes;i++)
  {
    cap>>frame;
    imshow("nn",frame); 
    cvtColor(frame,framehsv,CV_BGR2HSV);

    inRange(framehsv,Scalar(0,30,0),Scalar(50,150,255),framethr);

    framethr.convertTo(framethr,CV_32F);



    accumulate(framethr,frameaccF);

    waitKey(0);
  }
用于(int i=0;i>帧;
imshow(“nn”,帧);
CVT颜色(框架、框架HSV、CV_BGR2HSV);
范围(framehsv,标量(0,30,0),标量(50150255),framethr);
框架转换器(框架,CV_32F);
累计(framethr、frameaccF);
等待键(0);
}

谢谢,添加waitKey(1)效果很好(否则必须连续按下按钮),但为什么它不工作呢???@Lonewolf因为它不在for循环中waitKey在循环中的作用是什么,它不是只等待指定的时间并传递吗?是的,但你有一个imshow()在if循环中,如果您需要它,它就看不到waitkey()外loop@Lonewolf-。阅读投票最多的答案的最后一点。这就解释了原因。
tl;dr
:您需要
waitKey
,因为您需要给
highgui
库时间在屏幕上绘制图像。如果您不执行
waitKey
,则不会绘制任何内容,因为您没有给出它足够的绘图时间。