这是我的代码
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace std;
const int KEY_ENTER = 10;
const int KEY_ESC = 27;
const int KEY_1 = 49;
const int KEY_2 = 50;
const int KEY_3 = 51;
const int KEY_4 = 52;
const int KEY_5 = 53;
const int KEY_6 = 54;
const int DELAY = 30;
const string WIN_NAME = "Camera View";
const string NAME[6] = {"me", "serk", "prot", "vitkt", "st", "tara"};
struct pg
{
string name;
int cnt;
pg(): name(""), cnt (0) {};
pg(string s, int c) : name(s) , cnt(c) {};
};
pg crew[6];
int main()
{
for(int i = 0; i < 6; ++i)
crew[i] = pg(NAME[i], 0);
cv::VideoCapture cam;
cam.open(0);
cv::Mat frame;
pg cur = crew[0];
int c = 0;
for(;cam.isOpened();)
{
try
{
cam >> frame;
cv::imshow(WIN_NAME, frame);
int key = cv::waitKey(DELAY);
cur = (key >= KEY_1 && key <= KEY_6) ? crew[key - KEY_1] : cur;
if(KEY_ENTER == key)
cv::imwrite(cv::format("%s%d.jpg", cur.name.c_str(), cur.cnt++), frame);
if(KEY_ESC == key)
break;
} catch (cv::Exception e)
{
cout << e.err << endl;
}
}
cam.release();
return 0;
}
但我不能用相机拍摄视频=(我的电脑上有Ubuntu 12.04,
我完全完成了linux安装操作中的每一条指令我在谷歌上搜索了我的问题并安装了其他依赖项这个
- python opencv
- libhighgui 2.3
- libhighgui开发
- ffmpeg
- libgstreamer 0.10-0
- libv4l-0
- libv4l开发
- libxine2
- libunicap2
- libdc1394-22
以及我能找到的许多其他人。但它仍然不起作用
这很荒谬,但这段代码在我的笔记本电脑上有效,与ubuntu的发行版相同。我没有编译错误。
在终端gstreamer特性打开相机。有人知道该怎么办吗?请帮帮我。
我注意到它甚至不会从文件加载图片
代码示例#包括"opencv2/core/core.hpp"#包括"opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace std;
int main()
{
system("clear");
cv::Mat picture;
picture = cv::imread("boobies.jpg");
cout << picture.rows << endl;
cv::imshow("Smile", picture);
char ch;
cin >> ch;
cv::destroyWindow("Smile");
return 0;
}
尚未从项目文件夹加载图片
您忘记初始化cam
。必须使用具有int
作为参数的构造函数。
// the constructor that opens video file
VideoCapture(const string& filename);
// the constructor that starts streaming from the camera
VideoCapture(int device);
像这样做:
cv::VideoCapture cam(0);
cam.open(0);
此外,您可以使用cvCaptureFromCAM
:
CvCapture *capture;
capture = cvCaptureFromCAM( 0 );
这将分配并初始化您的捕获实例。
如果您在Opencv 2.4.6下,它已经被热修复:http://opencv.org/hot-fix-for-opencv-2-4-6.html