Created
July 15, 2023 07:27
-
-
Save Shaun289/3a8365ac449f9d6668486af7eaab12a3 to your computer and use it in GitHub Desktop.
opencv4cvml/ch03/BasicOp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* original source : https://github.com/sunkyoo/opencv4cvml/blob/master/ch03/BasicOp/main.cpp | |
* Cargo.toml | |
*. opencv = "0.82.0" | |
*/ | |
use opencv::core::*; | |
/* Point : https://docs.rs/opencv/0.83.0/opencv/core/struct.Point_.html | |
*/ | |
fn point_op() { | |
let mut pt1 = Point::default(); | |
pt1.x = 5; | |
pt1.y = 10; | |
let pt2 = Point::new(10, 30); | |
let pt3 = pt1 + pt2; | |
let pt4 = pt1 * 2; | |
let d1 = pt1.dot(pt2); // dot product. 5*10 + 10*30 | |
let b1 = pt1 == pt2; // FALSE | |
println!("{},{}", pt1.x, pt1.y); | |
println!("{},{}", pt2.x, pt2.y); | |
println!("{},{}", pt3.x, pt3.y); | |
println!("{},{}", pt4.x, pt4.y); | |
println!("{}", d1); | |
println!("{}", b1); | |
} | |
/* Size : https://docs.rs/opencv/0.83.0/opencv/core/struct.Size_.html | |
*/ | |
fn size_op() { | |
let mut sz1 = Size::default(); | |
let sz2 = Size::new(10, 20); | |
sz1.width = 5; | |
sz1.height = 10; | |
let sz3 = sz1 + sz2; | |
let sz4 = sz1 * 2; | |
let area1 = sz4.area(); | |
println!("{} {}", sz1.width, sz1.height); | |
println!("{} {}", sz2.width, sz2.height); | |
println!("{} {}", sz3.width, sz3.height); | |
println!("{} {}", sz4.width, sz4.height); | |
println!("sz4.area {}", area1); | |
} | |
/* Rect : https://docs.rs/opencv/0.83.0/opencv/core/struct.Rect_.html | |
*/ | |
fn rect_op() { | |
let rc1 = Rect::default(); | |
let rc2 = Rect::new(10, 10, 60, 40); | |
let rc3 = rc1 + Size::new(50, 40); // 50x40 from (0,0) | |
let rc4 = rc2 + Point::new(10, 10); // 60x40 from 20,20 | |
let rc5 = rc3 & rc4; // 30x20 from 20,20 | |
let rc6 = rc3 | rc4; // 80x60 from 0,0 | |
println!("{}x{} from {},{}", rc1.width, rc1.height, rc1.x, rc1.y); | |
println!("{}x{} from {},{}", rc2.width, rc2.height, rc2.x, rc2.y); | |
println!("{}x{} from {},{}", rc3.width, rc3.height, rc3.x, rc3.y); | |
println!("{}x{} from {},{}", rc4.width, rc4.height, rc4.x, rc4.y); | |
println!("{}x{} from {},{}", rc5.width, rc5.height, rc5.x, rc5.y); | |
println!("{}x{} from {},{}", rc6.width, rc6.height, rc6.x, rc6.y); | |
} | |
/* RotectedRect : https://docs.rs/opencv/0.83.0/opencv/core/struct.RotatedRect.html | |
*/ | |
fn rotated_rect_op() { | |
let rr1 = RotatedRect::new(Point2f::new(40.0, 30.0), Size2f::new(40.0, 20.0), 30.0).unwrap(); | |
let mut pts = [Point2f::default(); 4]; | |
let r = rr1.points(&mut pts); | |
/* | |
* 17.679493, 28.660255 | |
* 27.679493, 11.339746 | |
* 62.320507, 31.339745 | |
* 52.320507, 48.660255 | |
*/ | |
for point in &pts { | |
println!("{}, {}", point.x, point.y); | |
} | |
} | |
fn main() { | |
point_op(); | |
size_op(); | |
rect_op(); | |
rotated_rect_op(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment