erosion (in progress)
This commit is contained in:
parent
21272ee47b
commit
2f87321497
2 changed files with 16 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
|||
use camera::Camera;
|
||||
use opencv::{core::{bitwise_and, bitwise_and_def, bitwise_or_def, in_range, KeyPoint, KeyPointTraitConst, Mat, MatTraitConst, MatTraitConstManual, Ptr, Size, VecN, Vector, CV_64F, CV_8UC4}, features2d::{draw_matches_def, BFMatcher, ORB}, gapi::bgr2_luv, highgui::{self, MouseCallback}, imgcodecs::ImreadModes, imgproc::{self, cvt_color_def, gaussian_blur, gaussian_blur_def, sobel_def, COLOR_BGR2GRAY, COLOR_BGR2HLS}, prelude::{DescriptorMatcherTrait, DescriptorMatcherTraitConst, Feature2DTrait}};
|
||||
use opencv::{core::{bitwise_and, bitwise_and_def, bitwise_or_def, in_range, Kernel, KeyPoint, KeyPointTraitConst, Mat, MatTraitConst, MatTraitConstManual, Ptr, Size, Size_, VecN, Vector, CV_64F, CV_8UC4}, features2d::{draw_matches_def, BFMatcher, AKAZE, ORB}, gapi::{bgr2_luv, erode_def, GMat}, highgui::{self, MouseCallback}, imgcodecs::ImreadModes, imgproc::{self, cvt_color_def, gaussian_blur, gaussian_blur_def, get_structuring_element_def, sobel_def, MorphShapes, COLOR_BGR2GRAY, COLOR_BGR2HLS}, prelude::{DescriptorMatcherTrait, DescriptorMatcherTraitConst, Feature2DTrait}, ximgproc::erode};
|
||||
use webots::prelude::*;
|
||||
use std::{f64::consts::TAU, time::Duration};
|
||||
mod camera;
|
||||
|
@ -100,14 +100,17 @@ impl Robot for MyRobot {
|
|||
let lowerb = dbg!([(*LOWERB_H*255.) as u8,(*LOWERB_L*255.) as u8,(*LOWERB_S*255.) as u8,255]);
|
||||
let upperb = [(*UPPERB_H*255.) as u8,(*UPPERB_L*255.) as u8,(*UPPERB_S*255.) as u8,255];
|
||||
in_range(&blurred, &lowerb, &upperb, &mut mask_a).unwrap(); // h low
|
||||
let gmask = GMat::new(mask_a).unwrap();
|
||||
let kernel= get_structuring_element_def(MorphShapes::MORPH_CROSS as i32, Size_::new(2, 2)).unwrap();
|
||||
let eroded = erode_def(&gmask, &kernel).unwrap();
|
||||
// 103/180
|
||||
in_range(&blurred, &[0,30,4,255], &[52,209,63,255], &mut mask_b).unwrap(); // hh28
|
||||
highgui::imshow("a", &mask_a).unwrap();
|
||||
//highgui::imshow("a", &mask_a).unwrap();
|
||||
//highgui::imshow("b", &mask_b).unwrap();
|
||||
dbg!(blurred.row(240/2).unwrap().col(320/2).unwrap().data_bytes().unwrap());
|
||||
let mut range = opencv::core::Mat::default();
|
||||
bitwise_or_def(&mask_a, &mask_a, &mut mask).unwrap();
|
||||
bitwise_and(&img, &img, &mut range, &mask).unwrap();
|
||||
//bitwise_or_def(&mask_a, &mask_a, &mut mask).unwrap();
|
||||
bitwise_and(&img, &img, &mut range, &eroded.into()).unwrap();
|
||||
|
||||
highgui::imshow("edge", &range).unwrap();
|
||||
|
||||
|
@ -177,10 +180,10 @@ impl Robot for MyRobot {
|
|||
let mut left_speed = error * MAX_SPEED;
|
||||
let mut right_speed = -error * MAX_SPEED;
|
||||
|
||||
//self.left_motor.set_velocity(left_speed.clamp(-10., 10.));
|
||||
//self.right_motor.set_velocity(right_speed.clamp(-10., 10.));
|
||||
self.left_motor.set_velocity(0.);
|
||||
self.right_motor.set_velocity(0.);
|
||||
self.left_motor.set_velocity(left_speed.clamp(-10., 10.));
|
||||
self.right_motor.set_velocity(right_speed.clamp(-10., 10.));
|
||||
//self.left_motor.set_velocity(0.);
|
||||
//self.right_motor.set_velocity(0.);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
Webots Project File version R2023b
|
||||
perspectives: 000000ff00000000fd0000000300000000000001ca0000039ffc0200000001fb00000012005300630065006e0065005400720065006501000000000000039f000000000000000000000001000001f3000003e1fc0200000001fb0000001400540065007800740045006400690074006f00720000000016000003e10000003f00ffffff000000030000076c00000110fc0100000002fb0000000e0043006f006e0073006f006c0065010000000000000a010000000000000000fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c01000000000000076c0000000000000000000007800000040c00000004000000040000000100000008fc00000000
|
||||
simulationViewPerspectives: 000000ff000000010000000200000100000002af0100000002010000000101
|
||||
sceneTreePerspectives: 000000ff00000001000000030000001f000000c0000000fa0100000002010000000201
|
||||
perspectives: 000000ff00000000fd0000000300000000000001ca0000039ffc0200000001fb00000012005300630065006e0065005400720065006501000000000000039f000000000000000000000001000001f30000040cfc0200000001fb0000001400540065007800740045006400690074006f007200000000160000040c0000003f00ffffff000000030000045400000039fc0100000003fb0000000e0043006f006e0073006f006c0065010000000000000a010000000000000000fc00000000000004540000006900fffffffa000000000100000001fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c0100000000ffffffff0000006900fffffffb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c01000000000000076c0000000000000000000004540000025e00000004000000040000000100000008fc00000000
|
||||
simulationViewPerspectives: 000000ff000000010000000200000100000003520100000002010000000101
|
||||
sceneTreePerspectives: 000000ff00000001000000030000001f0000013e000000fa0100000002010000000201
|
||||
maximizedDockId: -1
|
||||
centralWidgetVisible: 1
|
||||
renderingMode: PLAIN
|
||||
orthographicViewHeight: 1
|
||||
textFiles: -1
|
||||
renderingDevicePerspectives: robot:camera7;0;0.133333;0;0.119402;1920;1080;1128;752;0
|
||||
consoles: Console:All:All
|
||||
renderingDevicePerspectives: robot:camera7;0;0.133333;0;0.119402
|
||||
|
|
Loading…
Reference in a new issue