bump some versions, reformat
MODIFY
Cargo.toml
Cargo.toml
@@ -31,5 +31,5 @@ libc = "0.2"
[build-dependencies]
pkg-config = "0.3"
-gcc = "0.3"
+cc = "1.0"
glob = "0.2"

MODIFY
build.rs
build.rs
-extern crate pkg_config;
+extern crate cc;
extern crate glob;
-extern crate gcc;
+extern crate pkg_config;
use glob::glob;
-use std::process::Command;
-use std::path::{ PathBuf };
-use std::fs;
-use std::fs::{ File, read_dir };
use std::ffi::OsString;
+use std::fs;
+use std::fs::{read_dir, File};
use std::io::Write;
+use std::path::PathBuf;
+use std::process::Command;
fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();
@@ -16,18 +16,23 @@ fn main() {
let opencv = pkg_config::Config::new().find("opencv").unwrap();
let mut search_paths = opencv.include_paths.clone();
search_paths.push(PathBuf::from("/usr/include"));
- let search_opencv = search_paths.iter().map( |p| {
+ let search_opencv = search_paths
+ .iter()
+ .map(|p| {
let mut path = PathBuf::from(p);
path.push("opencv2");
path
- }).find( { |path| read_dir(path).is_ok() });
- let actual_opencv = search_opencv
- .expect("Could not find opencv2 dir in pkg-config includes");
+ })
+ .find({ |path| read_dir(path).is_ok() });
+ let actual_opencv = search_opencv.expect("Could not find opencv2 dir in pkg-config includes");
println!("OpenCV lives in {:?}", actual_opencv);
println!("Generating code in {:?}", out_dir);
+ println!("cargo:rerun-if-changed=gen_rust.py");
+ println!("cargo:rerun-if-changed=hdr_parser.py");
- let mut gcc = gcc::Config::new();
+ let mut gcc = cc::Build::new();
+ gcc.cpp(true);
gcc.flag("-std=c++0x");
for path in opencv.include_paths {
gcc.include(path);
@@ -39,19 +44,35 @@ fn main() {
let modules = vec![
("core", vec!["core/types_c.h", "core/core.hpp"]), // utility, base
- ("imgproc", vec![ "imgproc/types_c.h", "imgproc/imgproc_c.h",
- "imgproc/imgproc.hpp" ]),
- ("highgui", vec![ "highgui/cap_ios.h",
+ (
+ "imgproc",
+ vec![
+ "imgproc/types_c.h",
+ "imgproc/imgproc_c.h",
+ "imgproc/imgproc.hpp",
+ ],
+ ),
+ (
+ "highgui",
+ vec![
+ "highgui/cap_ios.h",
"highgui/highgui.hpp",
"highgui/highgui_c.h",
//"highgui/ios.h"
- ]),
+ ],
+ ),
("features2d", vec!["features2d/features2d.hpp"]),
("photo", vec!["photo/photo_c.h", "photo/photo.hpp"]),
- ("video", vec![ "video/tracking.hpp", "video/video.hpp",
- "video/background_segm.hpp"]),
+ (
+ "video",
+ vec![
+ "video/tracking.hpp",
+ "video/video.hpp",
+ "video/background_segm.hpp",
+ ],
+ ),
("objdetect", vec!["objdetect/objdetect.hpp"]),
- ("calib3d", vec![ "calib3d/calib3d.hpp"])
+ ("calib3d", vec!["calib3d/calib3d.hpp"]),
];
let mut types = PathBuf::from(&out_dir);
@@ -77,12 +98,21 @@ fn main() {
if !Command::new("python2.7")
.args(&["gen_rust.py", "hdr_parser.py", &*out_dir, module.0])
- .args(&(module.1.iter().map(|p| {
+ .args(
+ &(module
+ .1
+ .iter()
+ .map(|p| {
let mut path = actual_opencv.clone();
path.push(p);
path.into_os_string()
- }).collect::<Vec<OsString>>()[..]))
- .status().unwrap().success() {
+ })
+ .collect::<Vec<OsString>>()[..]),
+ )
+ .status()
+ .unwrap()
+ .success()
+ {
panic!();
}
@@ -93,8 +123,12 @@ fn main() {
return_types.push("return_types.h");
let mut hub_return_types = File::create(return_types).unwrap();
for entry in glob(&(out_dir.clone() + "/cv_return_value_*.type.h")).unwrap() {
- writeln!(&mut hub_return_types, r#"#include "{}""#,
- entry.unwrap().file_name().unwrap().to_str().unwrap()).unwrap();
+ writeln!(
+ &mut hub_return_types,
+ r#"#include "{}""#,
+ entry.unwrap().file_name().unwrap().to_str().unwrap()
+ )
+ .unwrap();
}
for entry in glob("native/*.cpp").unwrap() {
@@ -104,20 +138,29 @@ fn main() {
gcc.file(entry.unwrap());
}
- gcc.cpp(true).include(".").include(&out_dir)
+ gcc.include(".")
+ .include(&out_dir)
.flag("-Wno-c++11-extensions");
gcc.compile("libocvrs.a");
for ref module in &modules {
- let e = Command::new("sh").current_dir(&out_dir).arg("-c").arg(
- format!("g++ {}.consts.cpp -o {}.consts `pkg-config --cflags --libs opencv`",
- module.0, module.0)
- ).status().unwrap();
+ let e = Command::new("sh")
+ .current_dir(&out_dir)
+ .arg("-c")
+ .arg(format!(
+ "g++ {}.consts.cpp -o {}.consts `pkg-config --cflags --libs opencv`",
+ module.0, module.0
+ ))
+ .status()
+ .unwrap();
assert!(e.success());
- let e = Command::new("sh").current_dir(&out_dir).arg("-c").arg(
- format!("./{}.consts > {}.consts.rs", module.0, module.0)
- ).status().unwrap();
+ let e = Command::new("sh")
+ .current_dir(&out_dir)
+ .arg("-c")
+ .arg(format!("./{}.consts > {}.consts.rs", module.0, module.0))
+ .status()
+ .unwrap();
assert!(e.success());
}
@@ -131,18 +174,31 @@ fn main() {
writeln!(&mut hub, r#"pub mod types {{"#).unwrap();
writeln!(&mut hub, " use libc::{{ c_void, c_char, size_t }};").unwrap();
for entry in glob(&(out_dir.clone() + "/*.type.rs")).unwrap() {
- writeln!(&mut hub, r#" include!(concat!(env!("OUT_DIR"), "/{}"));"#,
- entry.unwrap().file_name().unwrap().to_str().unwrap()).unwrap();
+ writeln!(
+ &mut hub,
+ r#" include!(concat!(env!("OUT_DIR"), "/{}"));"#,
+ entry.unwrap().file_name().unwrap().to_str().unwrap()
+ )
+ .unwrap();
}
writeln!(&mut hub, r#"}}"#).unwrap();
writeln!(&mut hub, "#[doc(hidden)] pub mod sys {{").unwrap();
writeln!(&mut hub, " use libc::{{ c_void, c_char, size_t }};").unwrap();
for entry in glob(&(out_dir.clone() + "/*.rv.rs")).unwrap() {
- writeln!(&mut hub, r#" include!(concat!(env!("OUT_DIR"), "/{}"));"#,
- entry.unwrap().file_name().unwrap().to_str().unwrap()).unwrap();
+ writeln!(
+ &mut hub,
+ r#" include!(concat!(env!("OUT_DIR"), "/{}"));"#,
+ entry.unwrap().file_name().unwrap().to_str().unwrap()
+ )
+ .unwrap();
}
for ref module in &modules {
- writeln!(&mut hub, r#" include!(concat!(env!("OUT_DIR"), "/{}.externs.rs"));"#, module.0).unwrap();
+ writeln!(
+ &mut hub,
+ r#" include!(concat!(env!("OUT_DIR"), "/{}.externs.rs"));"#,
+ module.0
+ )
+ .unwrap();
}
writeln!(&mut hub, "}}\n").unwrap();
}

MODIFY
examples/video_facedetect.rs
examples/video_facedetect.rs
extern crate opencv;
-use opencv::highgui;
use opencv::core;
+use opencv::highgui;
use opencv::imgproc;
use opencv::objdetect;
@@ -23,25 +23,59 @@ fn run() -> Result<(),String> {
continue;
}
let mut gray = try!(core::Mat::new());
- try!(imgproc::cvt_color(&frame, &mut gray, imgproc::CV_BGR2GRAY, 0));
+ try!(imgproc::cvt_color(
+ &frame,
+ &mut gray,
+ imgproc::CV_BGR2GRAY,
+ 0
+ ));
let mut reduced = try!(core::Mat::new());
- try!(imgproc::resize(&gray, &mut reduced, core::Size{width:0,height:0},
- 0.25f64, 0.25f64, imgproc::INTER_LINEAR));
+ try!(imgproc::resize(
+ &gray,
+ &mut reduced,
+ core::Size {
+ width: 0,
+ height: 0
+ },
+ 0.25f64,
+ 0.25f64,
+ imgproc::INTER_LINEAR
+ ));
let mut faces = ::opencv::types::VectorOfRect::new();
- try!(face.detect_multi_scale(&reduced, &mut faces, 1.1, 2,
+ try!(face.detect_multi_scale(
+ &reduced,
+ &mut faces,
+ 1.1,
+ 2,
objdetect::CV_HAAR_SCALE_IMAGE,
- core::Size{ width:30, height:30 },
- core::Size{ width:0, height:0 }));
+ core::Size {
+ width: 30,
+ height: 30
+ },
+ core::Size {
+ width: 0,
+ height: 0
+ }
+ ));
println!("faces: {}", faces.len());
for face in faces.iter() {
println!("face {:?}", face);
let scaled_face = core::Rect {
- x: face.x*4, y:face.y*4,
- width:face.width*4, height:face.height*4
+ x: face.x * 4,
+ y: face.y * 4,
+ width: face.width * 4,
+ height: face.height * 4,
};
- try!(core::rectangle(&frame, scaled_face,
- core::Scalar{ data:[0f64,-1f64,-1f64,-1f64] },
- 1, 8, 0));
+ try!(core::rectangle(
+ &frame,
+ scaled_face,
+ core::Scalar {
+ data: [0f64, -1f64, -1f64, -1f64]
+ },
+ 1,
+ 8,
+ 0
+ ));
}
try!(highgui::imshow(window, &frame));
if try!(highgui::wait_key(10)) > 0 {

MODIFY
examples/video_features.rs
examples/video_features.rs
extern crate opencv;
-use opencv::highgui;
use opencv::core;
-use opencv::imgproc;
use opencv::features2d;
+use opencv::highgui;
+use opencv::imgproc;
use opencv::features2d::FeatureDetector;
@@ -15,21 +15,39 @@ fn run() -> Result<(),String> {
println!("Using different camera");
cam = try!(highgui::VideoCapture::device(0));
}
- let mut orb = try!(features2d::ORB::new(500, 1.2f32, 8, 31, 0, 2,
- features2d::ORB_HARRIS_SCORE, 31));
+ let mut orb = try!(features2d::ORB::new(
+ 500,
+ 1.2f32,
+ 8,
+ 31,
+ 0,
+ 2,
+ features2d::ORB_HARRIS_SCORE,
+ 31
+ ));
loop {
let mut frame = try!(core::Mat::new());
try!(cam.read(&mut frame));
if try!(frame.size()).width > 0 {
let mut gray = try!(core::Mat::new());
- try!(imgproc::cvt_color(&frame, &mut gray, imgproc::CV_BGR2GRAY, 0));
+ try!(imgproc::cvt_color(
+ &frame,
+ &mut gray,
+ imgproc::CV_BGR2GRAY,
+ 0
+ ));
let mut kps = opencv::types::VectorOfKeyPoint::new();
// let mut desc = try!(core::Mat::new());
let mask = try!(core::Mat::new());
try!(orb.detect(&gray, &mut kps, &mask));
let mut display = try!(core::Mat::new());
- try!(features2d::draw_keypoints(&gray, &kps, &mut display,
- core::Scalar { data:[-1f64;4] }, features2d::DrawMatchesFlags_DEFAULT));
+ try!(features2d::draw_keypoints(
+ &gray,
+ &kps,
+ &mut display,
+ core::Scalar { data: [-1f64; 4] },
+ features2d::DrawMatchesFlags_DEFAULT
+ ));
try!(highgui::imshow(window, &display));
}
if try!(highgui::wait_key(10)) > 0 {

MODIFY
examples/video_to_gray.rs
examples/video_to_gray.rs
extern crate opencv;
use opencv::core;
-use opencv::imgproc;
use opencv::highgui;
+use opencv::imgproc;
fn run() -> Result<(), String> {
let window = "video capture";
@@ -18,7 +18,12 @@ fn run() -> Result<(),String> {
try!(cam.read(&mut frame));
if try!(frame.size()).width > 0 {
let mut gray = try!(core::Mat::new());
- try!(imgproc::cvt_color(&frame, &mut gray, imgproc::CV_BGR2GRAY, 0));
+ try!(imgproc::cvt_color(
+ &frame,
+ &mut gray,
+ imgproc::CV_BGR2GRAY,
+ 0
+ ));
try!(highgui::imshow(window, &gray));
}
if try!(highgui::wait_key(10)) > 0 {

MODIFY
src/lib.rs
src/lib.rs
#![allow(non_camel_case_types)]
extern crate libc;
+use libc::{c_char, c_void, size_t};
use std::ffi::{CStr, CString};
-use libc::{ c_void, c_char, size_t };
include!(concat!(env!("OUT_DIR"), "/hub.rs"));
pub fn mat() -> ::core::Mat {
::core::Mat::new().unwrap()
}
-

MODIFY
tests/get_tick_count.rs
tests/get_tick_count.rs
-extern crate opencv;
extern crate libc;
+extern crate opencv;
use opencv::core;
#[test]

MODIFY
tests/mat.rs
tests/mat.rs
@@ -6,7 +6,13 @@ fn mat_for_rows_and_cols() {
let typ = core::CV_8UC3;
let mat = core::Mat::new_rows_cols(400, 300, typ).unwrap();
let size = mat.size().unwrap();
- assert_eq!(core::Size { width: 300, height: 400 }, size);
+ assert_eq!(
+ core::Size {
+ width: 300,
+ height: 400
+ },
+ size
+ );
assert_eq!(core::CV_8U, mat.depth().unwrap());
assert_eq!(3, mat.channels().unwrap());
}

bump some versions, reformat