This repository has been archived by the owner on Feb 11, 2020. It is now read-only.
forked from Oxford-PTAM/PTAM-GPL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoSource_Linux_OpenCV.cc
73 lines (59 loc) · 1.94 KB
/
VideoSource_Linux_OpenCV.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Autor : Arnaud GROSJEAN (VIDE SARL)
* This implementation of VideoSource allows to use OpenCV as a source for the video input
* I did so because libCVD failed getting my V4L2 device
*
* INSTALLATION :
* - Copy the VideoSource_Linux_OpenCV.cc file in your PTAM directory
* - In the Makefile:
* - set the linkflags to
LINKFLAGS = -L MY_CUSTOM_LINK_PATH -lblas -llapack -lGVars3 -lcvd -lcv -lcxcore -lhighgui
* - set the videosource to
VIDEOSOURCE = VideoSource_Linux_OpenCV.o
* - Compile the project
* - Enjoy !
*
* Notice this code define two constants for the image width and height (OPENCV_VIDEO_W and OPENCV_VIDEO_H)
*/
#include "VideoSource.h"
#include <cvd/colourspace_convert.h>
#include <cvd/colourspaces.h>
#include <gvars3/instances.h>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace CVD;
//using namespace std;
using namespace GVars3;
//using namespace cv;
VideoSource::VideoSource()
{
std::cout << " VideoSource_Linux: Opening video source..." << std::endl;
cv::VideoCapture* cap = new cv::VideoCapture(0);
mptr = cap;
if(!cap->isOpened()){
std::cerr << "Unable to get the camera" << std::endl;
std::exit(-1);
}
std::cout << " ... got video source." << std::endl;
int width = (int) cap->get(cv::CAP_PROP_FRAME_WIDTH);
int height = (int) cap->get(cv::CAP_PROP_FRAME_HEIGHT);
mirSize = ImageRef(width, height);
};
ImageRef VideoSource::Size()
{
return mirSize;
};
void VideoSource::GetAndFillFrameBWandRGB(Image<byte> &imBW, Image<Rgb<byte> > &imRGB)
{
cv::VideoCapture* cap = (cv::VideoCapture*)mptr;
cv::Mat frame;
*cap >> frame;
cv::Mat bw(frame.size(), CV_8UC1, imBW.data(), imBW.row_stride());
cv::Mat rgb(frame.size(), CV_8UC3, imRGB.data(), imRGB.row_stride());
cv::cvtColor(frame, bw, cv::COLOR_BGR2GRAY);
cv::cvtColor(frame, rgb, cv::COLOR_BGR2RGB);
}