here is my code
#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;
}
but I cannot capture a video from camera. =( I've got Ubuntu 12.04 on my PC,
I did exactly every instruction in linux install istructions I googled my problem and installed additional dependencies this
- python-opencv
- libhighgui2.3
- libhighgui-dev
- ffmpeg
- libgstreamer0.10-0
- libv4l-0
- libv4l-dev
- libxine2
- libunicap2
- libdc1394-22
and many others which I can find.
but it still doesn't work.
It's ridiculous but this code works on my laptop, with the same distribution of ubuntu.
I have no compilation errors.
in terminal gstreamer-properties opens that camera. Does someone know what to do? Help me please.
I've noticed that it even doesn't load pictures from file
code example #include "opencv2/core/core.hpp" #include "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;
}
haven't load the picture from project folder