-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaskTest.cpp
More file actions
127 lines (100 loc) · 3.39 KB
/
Copy pathMaskTest.cpp
File metadata and controls
127 lines (100 loc) · 3.39 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* To Compile camtest.cpp and create executable camtest:
g++ -O2 `pkg-config --cflags --libs opencv` camtest.cpp -o camtest
To run:
./camtest
*/
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "RGB_V_et_al.cpp"
using namespace std;
using namespace cv;
#define WIDTH 320
#define HEIGHT 240
double width = 320;
double height = 240;
double im_width;
double im_height;
int main(){
VideoCapture capture(-1);
capture.set(CV_CAP_PROP_FRAME_WIDTH,width);
capture.set(CV_CAP_PROP_FRAME_HEIGHT,height);
im_width = capture.get(CV_CAP_PROP_FRAME_WIDTH);
im_height = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
printf("Setup completed\n");
Mat imgBGR;
if(!capture.isOpened()){
cout << "Camera not Working" << endl;
}
capture >> imgBGR;
printf("Captured image\n");
//Mat imgHSV(imgBGR.rows, imgBGR.cols, imgBGR.depth());
//cvtColor(imgBGR, imgHSV, CV_BGR2HSV);
Mat imgRed(imgBGR.rows, imgBGR.cols, imgBGR.depth());
Mat imgGre(imgBGR.rows, imgBGR.cols, imgBGR.depth());
Mat imgBlu(imgBGR.rows, imgBGR.cols, imgBGR.depth());
cout<<"Begin their conversion:\n";
cvtColor(imgBGR, imgRed, CV_BGR2HSV);//for some reason needed
cvtColor(imgBGR, imgGre, CV_BGR2HSV);//for some reason needed
cvtColor(imgBGR, imgBlu, CV_BGR2HSV);//for some reason needed
cout<<"done\n";
cout<<"Begin our conversion:\n";
rgbToAvgM(&imgBGR, &imgRed, 100, 0, 0);
rgbToAvgM(&imgBGR, &imgGre, 0, 100, 0);
rgbToAvgM(&imgBGR, &imgBlu, 0, 0, 100);
cout<<"done\n";
printf("Write original image\n");
imwrite("preImg.png", imgBGR);
Vec3b intensity;
int pos;
uchar red[WIDTH * HEIGHT];
uchar gre[WIDTH * HEIGHT];
uchar blu[WIDTH * HEIGHT];
uchar sum;
for(int c = 0; c < WIDTH; c++)
{
for(int r = 0; r < HEIGHT; r++)
{
intensity = imgBGR.at<Vec3b>(r, c);
pos = WIDTH * r + c;
red[pos] = intensity.val[2];
gre[pos] = intensity.val[1];
blu[pos] = intensity.val[0];
sum = (red[pos] / 3 + gre[pos] / 3 + blu[pos] / 3);
//cout<<(uint) sum<<endl;
if(sum < 150)
{
(imgBGR.at<Vec3b>(r, c)).val[0] = 0;
(imgBGR.at<Vec3b>(r, c)).val[1] = 0;
(imgBGR.at<Vec3b>(r, c)).val[2] = 0;
}
}
}
cout<<"Write color images\n";
vector<Mat> colors;
split(imgRed, colors);
imwrite("imgRed.png", colors[2]);
split(imgGre, colors);
imwrite("imgGre.png", colors[2]);
split(imgBlu, colors);
imwrite("imgBlu.png", colors[2]);
printf("Write altered image\n");
imwrite("postImg.png", imgBGR);
/*
vector<Mat> hsv;
split(imgHSV, hsv);
vector<Mat> hsv2;
split(imgHSV2, hsv2);
printf("Split image into components\n");
imwrite("imgH.png",hsv[0]);
imwrite("imgH2.png",hsv2[0]);
imwrite("imgS.png",hsv[1]);
imwrite("imgS2.png",hsv2[1]);
imwrite("imgV.png",hsv[2]);
imwrite("imgV2.png",hsv2[2]);
imwrite("img.png",imgHSV);
imwrite("img2.png",imgHSV2);
*/
printf("Wrote images\n");
return 0;
}