|
1 | | -use crate::config::ColorProfile; |
| 1 | +use crate::config::{ColorProfile, Side}; |
2 | 2 |
|
3 | 3 | use super::{image_prep::resize, MatWrapper, PosVector, VisualDetection, VisualDetector, Yuv}; |
4 | 4 | use opencv::{ |
@@ -153,57 +153,60 @@ impl VisualDetector<f64> for GateCV { |
153 | 153 | .unwrap() |
154 | 154 | }); |
155 | 155 |
|
156 | | - if let Some(contour) = max_contour_red { |
157 | | - let area = contour_area_def(&contour)?; |
158 | | - #[cfg(feature = "logging")] |
159 | | - logln!("AREA: {area}"); |
160 | | - |
161 | | - if area > *MIN_AREA && area < *MAX_AREA { |
162 | | - let rect = min_area_rect(&contour)?; |
163 | | - |
164 | | - let mut box_rect = Mat::default(); |
165 | | - box_points(rect, &mut box_rect)?; |
166 | | - |
167 | | - let box_vec: Vec<Vec<f32>> = box_rect.to_vec_2d()?; |
168 | | - |
169 | | - let zero = box_vec[0].clone(); |
170 | | - let one = box_vec[1].clone(); |
171 | | - let two = box_vec[2].clone(); |
172 | | - |
173 | | - let edge1 = (one[0] - zero[0], one[1] - zero[1]); |
174 | | - let edge2 = (two[0] - one[0], two[1] - one[1]); |
175 | | - |
176 | | - let edge1mag = (edge1.0.powf(2.0) + edge1.1.powf(2.0)).sqrt(); |
177 | | - let edge2mag = (edge2.0.powf(2.0) + edge2.1.powf(2.0)).sqrt(); |
178 | | - let longest_edge = if edge2mag > edge1mag { edge2 } else { edge1 }; |
179 | | - |
180 | | - let mut angle = -(longest_edge.0 / longest_edge.1).atan().to_degrees(); |
181 | | - |
182 | | - angle = ((angle + 180.0) % 360.0) - 180.0; |
183 | | - if angle < -90.0 { |
184 | | - angle += 180.0; |
| 156 | + if let Some(contour_red) = max_contour_red { |
| 157 | + if let Some(contour_black) = max_contour_black { |
| 158 | + let red_rect = min_area_rect(&contour_red).unwrap(); |
| 159 | + let black_rect = min_area_rect(&contour_black).unwrap(); |
| 160 | + let center_red = red_rect.center; |
| 161 | + let center_black = black_rect.center; |
| 162 | + |
| 163 | + let red_angle = red_rect.angle; |
| 164 | + let black_angle = black_rect.angle; |
| 165 | + if (red_angle - black_angle).abs() > 20.0 { |
| 166 | + let red_x = center_red.x; |
| 167 | + let black_x = center_black.x; |
| 168 | + let red_y = center_red.y; |
| 169 | + let black_y = center_black.y; |
| 170 | + if (red_x - black_x).abs() < 50.0 { |
| 171 | + let side; |
| 172 | + if black_y > red_y { |
| 173 | + side = Side::Right; |
| 174 | + } else { |
| 175 | + side = Side::Left; |
| 176 | + } |
| 177 | + let pole_x = (red_x + black_x) / 2; |
| 178 | + let pole_y = (red_y + black_y) / 2; |
| 179 | + } |
185 | 180 | } |
186 | | - |
187 | | - println!("{angle:?}"); |
188 | | - |
189 | | - let center_adjusted_x = rect.center.x as f64; |
190 | | - let center_adjusted_y = rect.center.y as f64; |
191 | | - |
192 | | - Ok(vec![VisualDetection { |
193 | | - class: true, |
194 | | - position: PosVector::new( |
195 | | - center_adjusted_x, |
196 | | - center_adjusted_y, |
197 | | - 0., |
198 | | - angle as f64, |
199 | | - ), |
200 | | - }]) |
201 | | - } else { |
202 | | - Ok(vec![VisualDetection { |
203 | | - class: false, |
204 | | - position: PosVector::new(0., 0., 0., 0.), |
205 | | - }]) |
206 | 181 | } |
| 182 | + // let area = contour_area_def(&contour_red)?; |
| 183 | + // #[cfg(feature = "logging")] |
| 184 | + // logln!("AREA: {area}"); |
| 185 | + |
| 186 | + // if area > *MIN_AREA && area < *MAX_AREA { |
| 187 | + // let rect = min_area_rect(&contour_red)?; |
| 188 | + |
| 189 | + // let mut box_rect = Mat::default(); |
| 190 | + // box_points(rect, &mut box_rect)?; |
| 191 | + |
| 192 | + // let center_adjusted_x = rect.center.x as f64; |
| 193 | + // let center_adjusted_y = rect.center.y as f64; |
| 194 | + |
| 195 | + // Ok(vec![VisualDetection { |
| 196 | + // class: true, |
| 197 | + // position: PosVector::new( |
| 198 | + // center_adjusted_x, |
| 199 | + // center_adjusted_y, |
| 200 | + // 0., |
| 201 | + // angle as f64, |
| 202 | + // ), |
| 203 | + // }]) |
| 204 | + // } else { |
| 205 | + // Ok(vec![VisualDetection { |
| 206 | + // class: false, |
| 207 | + // position: PosVector::new(0., 0., 0., 0.), |
| 208 | + // }]) |
| 209 | + // } |
207 | 210 | } else { |
208 | 211 | Ok(vec![VisualDetection { |
209 | 212 | class: false, |
|
0 commit comments