-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlt3measred.cpp
156 lines (133 loc) · 3.96 KB
/
lt3measred.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
* The code below is meant to detect whether the Red Ruby
* is present. The starategy implemented by the code is not very effective.
* Study the code so that you understand what the strategy is and how
* it is implemented. Then design and implement a better startegy.
*
* */
#include <iostream>
#include "E101.h"
using namespace std;
bool red_true(int totred, int totgreen, int totblue){
return(((totred > (2*totblue)) && (totred > (2*totgreen)))); //the second half here, compares against the blue/green values in the diamond with the spot on the white piece of paper.
}
int main()
{
int err = init(0);
cout<<" Hello. err="<<err<<endl;
int totred = 0; // combined value of all red values of all pixels
int totgreen = 0; //combined value of all green pixels
int totblue = 0; //combined value of all blue value
int totint = 0; // ditto for grey
//int notrubytotred = 0; // combined value of all red values of all pixels
//int notrubytotgreen = 0; //combined value of all green pixels
//int notrubytotblue = 0; //combined value of all blue value
//int notrubytotint = 0; // ditto for grey
float redness = 0; // ratio of redness to greyness
open_screen_stream();
// make 1000 runs
for(int countrun =0; countrun <1000; countrun=countrun+1)
{
take_picture();
update_screen();
totred = 0;
totgreen = 0;
totblue = 0;
totint = 0;
redness = 0;
// for all pixels in latest image
totred = totred + (int)get_pixel(120,160,0);
totgreen = totgreen + (int)get_pixel(120,160,1);
totblue = totblue + (int)get_pixel(120,160,2);
totint = totint + (int)get_pixel(120,160,3);
//notrubytotred = notrubytotred + (int)get_pixel(50,50,0);
//notrubytotgreen = notrubytotgreen + (int)get_pixel(50,50,1);
//notrubytotblue= notrubytotblue + (int)get_pixel(50,50,2);
//notrubytotint = notrubytotint + (int)get_pixel(50,50,3);
int left = 320;
int right = 0;
int top = 240;
int bottom = 0;
int firstleftval = left;
int firstrightval = right;
int firsttopval = top;
int firstbottomval = bottom;
for(int i =0; i <= 1; i++){
take_picture();
for (int row = 0 ; row<=240 ; row=row+1)
{
for (int col=0; col<=320; col=col+1)
{
if(red_true((int)get_pixel(row,col,0),(int)get_pixel(row,col,1),(int)get_pixel(row,col,2))){
if(col < left){
left = col;
}
if(col > right){
right = col;
}
if(row < top){
top = row;
}
if(row > top){
bottom = row;
}
}
firstleftval = left;
firstrightval = right;
firsttopval = top;
firstbottomval = bottom;
}
}
}
cout<<firstleftval<<endl;
cout<<firstrightval<<endl;
cout<<firsttopval<<endl;
cout<<firstbottomval<<endl;
for (int row = 0 ; row<=240 ; row=row+1)
{
for (int col=0; col<=320; col=col+1)
{
if(red_true((int)get_pixel(row,col,0),(int)get_pixel(row,col,1),(int)get_pixel(row,col,2))){
if(col < left){
left = col;
}
if(col > right){
right = col;
}
if(row < top){
top = row;
}
if(row > top){
bottom = row;
}
}
}
}
if((firstleftval == left && firstrightval == right) || (firsttopval == top && firstbottomval == bottom)){
cout<<"RUBY IS SECURED"<<endl;
} else {
cout<<"THE RUBY IS STOLEN"<<endl;
return 0;
}
/*if(red_true(totred, totgreen, totblue)){
cout<<"RUBY IS SECURED"<<endl;
} else {
cout<<"THE RUBY IS STOLEN"<<endl;
return 0;
} */
//redness = (float)totred/(50*((float)totgreen*(float)totblue));
//cout<<" countrun="<<countrun;
//cout<<" Total red "<< totred;
//cout<<" Total green "<< totgreen;
//cout<<" Total blue "<< totblue;
//cout<<" Total int "<< totint;
//cout<<" Total notrubyred "<< notrubytotred;
//cout<<" Total notrubygreen "<< notrubytotgreen;
//cout<<" Total notrubyblue "<< notrubytotblue;
//cout<<" Total notrubyint "<< notrubytotint;
cout<<" Total int "<< totint<<endl;
//cout<<" Redness "<< redness<<endl;
sleep1(100); // slow down a bit to make display easier
}
close_screen_stream();
}