camtest.cpp
1 |
/* To Compile camtest.cpp and create executable camtest:
|
---|---|
2 |
g++ -O2 `pkg-config --cflags --libs opencv` camtest.cpp -o camtest
|
3 |
|
4 |
To run:
|
5 |
./camtest
|
6 |
*/
|
7 |
|
8 |
|
9 |
#include <iostream> |
10 |
#include <stdio.h> |
11 |
#include <opencv2/opencv.hpp> |
12 |
using namespace std; |
13 |
using namespace cv; |
14 |
|
15 |
#define WIDTH 320 |
16 |
#define HEIGHT 240 |
17 |
|
18 |
double width = 320; |
19 |
double height = 240; |
20 |
|
21 |
double im_width;
|
22 |
double im_height;
|
23 |
|
24 |
int main(){
|
25 |
VideoCapture capture(-1);
|
26 |
capture.set(CV_CAP_PROP_FRAME_WIDTH,width); |
27 |
capture.set(CV_CAP_PROP_FRAME_HEIGHT,height); |
28 |
im_width = capture.get(CV_CAP_PROP_FRAME_WIDTH); |
29 |
im_height = capture.get(CV_CAP_PROP_FRAME_HEIGHT); |
30 |
|
31 |
printf("Setup completed\n");
|
32 |
|
33 |
Mat imgBGR; |
34 |
if(!capture.isOpened()){
|
35 |
cout << "Camera not Working" << endl;
|
36 |
} |
37 |
capture >> imgBGR; |
38 |
printf("Captured image\n");
|
39 |
vector<Mat> bgr; |
40 |
split(imgBGR,bgr); |
41 |
|
42 |
printf("Split image into components\n");
|
43 |
imwrite("imgB.png",bgr[0]); |
44 |
imwrite("imgG.png",bgr[1]); |
45 |
imwrite("imgR.png",bgr[2]); |
46 |
imwrite("img.png",imgBGR);
|
47 |
printf("Wrote images\n");
|
48 |
return 0; |
49 |
} |