无法访问我的网络摄像头opencv ubuntu
Cannot access to my webcam opencv ubuntu
这是我的代码
#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
相关文章:
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- 使用OpenCV和覆盆子上的多个网络摄像头拍摄延时摄影,出现多个V4L错误
- 从 OpenCV 3 切换到 OpenCV 4 会导致网络摄像头以最大 5 fps 的速度录制,而不是通常的 30 f
- OpenCV没有显示来自Macbook网络摄像头的视频
- 使用OpenCV和C++在按键上截取网络摄像头源的屏幕截图
- 使用OpenCV访问摄像头(通过GSTREAMER)
- 如何使用OpENCV解决图像处理摄像头IO延迟
- systemd无法通过opencv访问摄像头
- 无法使用OpenCV打开两个摄像头-多线程摄像头读取
- TensorFlow OpenCV网络摄像头悬挂
- Opencv Aruco标记在工业摄像头上未得到认可
- EasyAr访问摄像头框架作为OpenCV垫子
- 在OpENCV中创建摄像头进料的马赛克,但不会大大延迟
- 意外的摄像头校准结果与JPEG图像和EXIF方向上的OPENCV结果
- OpenCV 将剪影与网络摄像头流隔离
- OpenCV-从C/C++中的默认网络摄像头获取图片-GTK问题
- 在 OpenCV 中,设置曝光会导致我的网络摄像头软件无法自动调整曝光
- 无法使用OpenCV从辅助网络摄像头读取VideoCapture中的帧
- 使用Opencv直接从网络摄像头获取灰度图像
- 无法访问我的网络摄像头opencv ubuntu