-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgs-bw.cpp
More file actions
51 lines (49 loc) · 1.05 KB
/
gs-bw.cpp
File metadata and controls
51 lines (49 loc) · 1.05 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
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace std;
using namespace cv;
//Arnesh Kumar Issar
int main(int argc, char const *argv[])
{
Mat img= imread("/home/arnesh/IP/samps/joker.jpg",1);
int cols=img.cols;
int rows=img.rows;
//Unequal Width (.11,.58,.299)
Mat a (rows,cols,CV_8UC1,Scalar(0));
for (int j = 0; j < cols; j++)
{
for (int i = 0; i < rows; i++)
{
int ib= img.at<Vec3b>(i,j)[0];
int ig= img.at<Vec3b>(i,j)[1];
int ir= img.at<Vec3b>(i,j)[2];
int igr= ((.11*ib)+(.58*ig)+(.299*ir));
a.at<uchar>(i,j)=igr;
}
}
Mat b (rows,cols,CV_8UC1,Scalar(0));
int th=1; //Threshold Valu
namedWindow("B&W",WINDOW_NORMAL);
createTrackbar("Threshold","B&W",&th,255);
while (1)
{
for (int j = 0; j < cols; j++)
{
for (int i = 0; i < rows; i++)
{
if (a.at<uchar>(i,j)<=th)
{
b.at<uchar>(i,j)=0;
}
else if (a.at<uchar>(i,j)>=th)
{
b.at<uchar>(i,j)=255;
}
}
}
imshow("B&W",b);
waitKey(1);
}
}