OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 2874|回复: 0

有偿!实时视频帧数为-1,这是什么意思啊

[复制链接]
发表于 2018-5-23 14:48:53 | 显示全部楼层 |阅读模式
代码如下,
#include "stdafx.h"
#include <time.h>  
#include <windows.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
string imgPath = "网络摄像头地址";
Mat Srcimg, Grayimg, dstimg,c;
Mat a; //                 Canny 边缘检测相关变量
int b = 1;   //同上
/*FileStorage fsWrite;
string FilePath = "mode.yaml";*/
static void on_Canny(int, void*);
int _tmain(int argc, _TCHAR* argv[])
{
  /*bool n =0;*/
  VideoCapture capture(imgPath);  //调用摄像头
  /*double FPS, t = 0;
  char string[10];*/
  double rate = capture.get(CV_CAP_PROP_FPS);
  cout << "视频帧数为" << rate << endl;
  if (!capture.isOpened())
  {
   printf("can't open capture\n");
   waitKey(0);
   getchar();
   return -1;
  }
  else
  {
   printf("you can open this!\n");
  }
  namedWindow("定位",1);

  /*capture >> c;
  imshow("定位", c);*/


while (1)
{

  capture >> Srcimg;     //逐帧显示,一直循环

  imshow("原图!\n", Srcimg);
  waitKey(10);
  dstimg.create(Srcimg.size(), Srcimg.type());   //建立一个和Srcimg一样大小,一样类型的矩阵dstimg
  cvtColor(Srcimg, Grayimg, COLOR_BGR2GRAY);     //将图像转换为灰度图
  //namedWindow("效果图",WINDOW_AUTOSIZE);
  createTrackbar("参数值:", "效果图 Canny边缘检测", &b, 120, on_Canny);//建立一个滑动条
  on_Canny(0, 0);

  if (waitKey(30) == 27)   //按键esc退出
  {
   break;
  }
  if(Srcimg.empty())
  {
   break;
  }
  /*if ()
  {
   break;
  }*/
}
return 0;
}

void on_Canny(int, void*)   //回掉函数
{
blur(Grayimg, a, Size(2, 3));
Canny(a, a, b, b * 5, 3);
dstimg = Scalar::all(0);
Srcimg.copyTo(dstimg, a);
imshow("效果图 Canny边缘检测", dstimg);
}

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-3-29 07:21 , Processed in 0.013563 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表