-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecodetry.cpp
80 lines (57 loc) · 1.74 KB
/
decodetry.cpp
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
#include<iostream>
#include<fstream>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
//converting a binary string into decimal number
int getintvalue(string s){
int val =0;
for(int i=0 ; i<s.size() ; i++){
val = val*2 + (int)s[i]-48;
}
return val;
}
int main(int argc , char** argv){
string temp = "";
string message="";
int bits =0;
int flag;
int count=0;
Mat image = imread(argv[1]);
if(image.empty()){
cout << "An error occured due to image"<<endl;
return -1;
}
for(int row= 0 ; row <= image.rows ; row++){
for(int col = 0; col <= image.cols ; col++){
for(int color = 0; color < 3 ; color++){
Vec3b pixel = image.at<Vec3b>(Point(row,col));
//getting bits that are stored in the picture
if((int)pixel.val[color] &1){
temp.append("1");
}
else{
temp.append("0");
}
bits++;
if(bits == 7){
flag = getintvalue(temp);
//cout<<flag<<endl;
//when we reach endoffile we exit the loop
if(flag == 0){
goto exiting;
}
else{
char x = (char)flag;
// cout<<x<<endl;
message.append(&x,1);
temp ="";
bits=0;
}
}
}
}
}
exiting:;
cout << message <<endl;
}