Skip to content

Commit

Permalink
build fix (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pzixel authored May 20, 2018
1 parent 1fd5c42 commit 4637295
Show file tree
Hide file tree
Showing 29 changed files with 67 additions and 147 deletions.
2 changes: 1 addition & 1 deletion examples/calc_hist.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
extern crate cv;

use cv::*;
use cv::highgui::*;
use cv::imgcodecs::ImageReadMode;
use cv::*;

fn main() {
////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion examples/camshift.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate cv;
use cv::*;
use cv::highgui::*;
use cv::imgproc::*;
use cv::video::tracking::*;
use cv::videoio::*;
use cv::*;

struct SelectionStatus {
selection: Rect,
Expand Down
2 changes: 1 addition & 1 deletion examples/display_image.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// This resembles the OpenCV read image example code:
// http://docs.opencv.org/3.1.0/db/deb/tutorial_display_image.html
extern crate cv;
use cv::*;
use cv::highgui::*;
use cv::imgcodecs::ImageReadMode;
use cv::*;

fn main() {
let args: Vec<_> = std::env::args().collect();
Expand Down
11 changes: 2 additions & 9 deletions examples/face_detect.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate cv;

use cv::*;
use cv::highgui::*;
use cv::imgcodecs::*;
use cv::objdetect::CascadeClassifier;
use cv::*;
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
Expand All @@ -29,14 +29,7 @@ fn main() {
// we draw each of them on the image
result
.iter()
.map(|&r| {
mat.rectangle_custom(
r.scale(1.2),
Scalar::new(255, 255, 0, 255),
10,
LineType::Line8,
)
})
.map(|&r| mat.rectangle_custom(r.scale(1.2), Scalar::new(255, 255, 0, 255), 10, LineType::Line8))
.count();
mat.show("window", 0).unwrap();
}
17 changes: 4 additions & 13 deletions examples/hog.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
extern crate cv;
extern crate getopts;

use cv::*;
use cv::highgui::*;
use cv::imgcodecs::*;
use cv::objdetect::*;
use cv::*;

#[cfg(feature = "cuda")]
use cv::cuda::GpuHog as Hog;
Expand Down Expand Up @@ -46,9 +46,7 @@ fn run() -> Result<()> {
let show = matches.opt_present("s");
let measure = matches.opt_present("m");

let dir = matches
.opt_str("d")
.expect("You need to provide the directory");
let dir = matches.opt_str("d").expect("You need to provide the directory");

if show {
highgui_named_window("window", WindowFlag::Autosize).unwrap();
Expand All @@ -70,11 +68,7 @@ fn run() -> Result<()> {

fn run_detect_for_image<P: AsRef<Path>, OD: ObjectDetect>(detector: &mut OD, path: P, show: bool, measure: bool) {
let mut buf = Vec::new();
let filename = path.as_ref()
.file_stem()
.unwrap()
.to_string_lossy()
.into_owned();
let filename = path.as_ref().file_stem().unwrap().to_string_lossy().into_owned();
let frame_num = filename.parse::<usize>().unwrap();
File::open(path).unwrap().read_to_end(&mut buf).unwrap();
let mat = Mat::image_decode(&buf, ImageReadMode::Grayscale);
Expand All @@ -92,10 +86,7 @@ fn run_detect_for_image<P: AsRef<Path>, OD: ObjectDetect>(detector: &mut OD, pat
}

if show {
results
.iter()
.map(|&(r, _w)| mat.rectangle(r.scale(0.6)))
.count();
results.iter().map(|&(r, _w)| mat.rectangle(r.scale(0.6))).count();
mat.show("window", 0).unwrap();
}
}
Expand Down
9 changes: 2 additions & 7 deletions examples/hs_hist.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate cv;

use cv::*;
use cv::highgui::*;
use cv::imgcodecs::ImageReadMode;
use cv::imgproc::ColorConversion;
use cv::*;

fn main() {
////////////////////////////////
Expand Down Expand Up @@ -64,12 +64,7 @@ fn main() {
let intensity = (bin_val * 255.0 / max_val) as i32;
let rect = Rect::new(h * scale + 1, s * scale + 1, scale - 1, scale - 1);

hist_image.rectangle_custom(
rect,
Scalar::all(intensity),
LineType::Filled as i32,
LineType::Line8,
);
hist_image.rectangle_custom(rect, Scalar::all(intensity), LineType::Filled as i32, LineType::Line8);
}
}

Expand Down
13 changes: 3 additions & 10 deletions src/cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use super::core::*;
use super::errors::*;
use super::objdetect::{CSvmDetector, HogParams, ObjectDetect, SvmDetector};
use ::*;
use failure::Error;
use std::ffi::CString;
use std::os::raw::{c_char, c_double, c_int};
use std::path::Path;
use *;

/// Opaque data struct for C/C++ cv::cuda::GpuMat bindings
#[derive(Clone, Copy, Debug)]
Expand Down Expand Up @@ -239,11 +239,7 @@ impl GpuHog {
unsafe {
cv_cuda_hog_detect(self.inner, mat.inner, &mut found);
}
found
.unpack()
.into_iter()
.map(|r| (r, 0f64))
.collect::<Vec<_>>()
found.unpack().into_iter().map(|r| (r, 0f64)).collect::<Vec<_>>()
}

/// Detects and returns the results with confidence (scores)
Expand Down Expand Up @@ -409,10 +405,7 @@ impl ObjectDetect for GpuCascade {
fn detect(&self, image: &Mat) -> Vec<(Rect, f64)> {
let mut gpu_mat = GpuMat::default();
gpu_mat.upload(image);
self.detect_multiscale(&gpu_mat)
.into_iter()
.map(|r| (r, 0.0))
.collect()
self.detect_multiscale(&gpu_mat).into_iter().map(|r| (r, 0.0)).collect()
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/features2d/descriptor_matcher.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Provide types for matching keypoint descriptors
use ::*;
use std::os::raw::{c_char, c_int};
use *;

enum CDescriptorMatcher {}

Expand Down Expand Up @@ -131,12 +131,7 @@ impl DescriptorMatcher {
pub fn knn_match(&self, query_descriptors: &Mat, k: usize) -> Vec<Vec<DMatch>> {
let mut matches = CVec::<CVec<DMatch>>::default();
unsafe {
cv_matcher_knn_match(
self.value,
query_descriptors.inner,
k as c_int,
&mut matches,
);
cv_matcher_knn_match(self.value, query_descriptors.inner, k as c_int, &mut matches);
}
matches.unpack()
}
Expand Down
2 changes: 1 addition & 1 deletion src/features2d/mser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Provide the type that encapsulates all the parameters of the MSER extraction algorithm
use ::*;
use core::*;
use std::os::raw::*;
use *;

enum CMSER {}

Expand Down
21 changes: 3 additions & 18 deletions src/features2d/sift.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Provide the type that encapsulates all the parameters of the SIFT extraction algorithm
use super::*;
use ::*;
use core::*;
use std::os::raw::*;
use *;

enum CSIFT {}

Expand Down Expand Up @@ -40,15 +40,7 @@ impl SIFT {
edge_threshold: f64,
sigma: f64,
) -> Self {
let sift = unsafe {
cv_sift_new(
features,
octave_layers,
contrast_threshold,
edge_threshold,
sigma,
)
};
let sift = unsafe { cv_sift_new(features, octave_layers, contrast_threshold, edge_threshold, sigma) };
SIFT { value: sift }
}
}
Expand Down Expand Up @@ -120,14 +112,7 @@ impl Feature2D for SIFT {
let mut keypoints = CVec::<KeyPoint>::default();
let descriptors = CMat::new();
unsafe {
cv_sift_detect_and_compute(
self.value,
image.inner,
mask.inner,
&mut keypoints,
descriptors,
false,
);
cv_sift_detect_and_compute(self.value, image.inner, mask.inner, &mut keypoints, descriptors, false);
}
(keypoints.unpack(), Mat::from_raw(descriptors))
}
Expand Down
11 changes: 2 additions & 9 deletions src/features2d/surf.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Provide the type that encapsulates all the parameters of the SURF extraction algorithm
use super::*;
use ::*;
use core::*;
use std::os::raw::*;
use *;

enum CSURF {}

Expand Down Expand Up @@ -106,14 +106,7 @@ impl Feature2D for SURF {
let mut keypoints = CVec::<KeyPoint>::default();
let descriptors = CMat::new();
unsafe {
cv_surf_detect_and_compute(
self.value,
image.inner,
mask.inner,
&mut keypoints,
descriptors,
false,
);
cv_surf_detect_and_compute(self.value, image.inner, mask.inner, &mut keypoints, descriptors, false);
}
(keypoints.unpack(), Mat::from_raw(descriptors))
}
Expand Down
2 changes: 1 addition & 1 deletion src/highgui.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! highgui: high-level GUI
use failure::Error;
use mat::*;
use std::ffi::CString;
use std::mem;
use std::os::raw::{c_char, c_int, c_void};
use std::ptr;
use mat::*;

extern "C" {
fn cv_named_window(name: *const c_char, flags: WindowFlag);
Expand Down
4 changes: 2 additions & 2 deletions src/imgcodecs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Image file reading and writing, see [OpenCV
//! imgcodecs](http://docs.opencv.org/3.1.0/d4/da8/group__imgcodecs.html).
use ::*;
use errors::*;
use failure::Error;
use mat::*;
use std::ffi::CString;
use std::os::raw::c_char;
use std::path::Path;
use failure::Error;
use *;

extern "C" {
fn cv_imread(input: *const c_char, flags: ImageReadMode) -> *mut CMat;
Expand Down
10 changes: 3 additions & 7 deletions src/imgproc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Image processing, see [OpenCV
//! imgproc](http://docs.opencv.org/3.1.0/d7/dbd/group__imgproc.html).
use super::*;
use super::core::*;
use super::*;
use std::os::raw::{c_double, c_float, c_int};

// =============================================================================
Expand Down Expand Up @@ -120,7 +120,7 @@ pub enum HistogramComparisionMethod {
/// [threshold](../struct.Mat.html#method.threshold).
#[repr(C)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
#[allow(non_camel_case_types, missing_docs)]
#[allow(missing_docs)]
pub enum ThresholdType {
Binary = 0,
BinaryInv = 1,
Expand Down Expand Up @@ -549,10 +549,6 @@ impl Mat {
}

fn matrix_to_vec<T, MElem: AsRef<[T]>, M: AsRef<[MElem]>>(value: M) -> Vec<*const T> {
value
.as_ref()
.iter()
.map(|x| x.as_ref().as_ptr())
.collect::<Vec<_>>()
value.as_ref().iter().map(|x| x.as_ref().as_ptr()).collect::<Vec<_>>()
}
}
26 changes: 11 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ extern crate bytes;
extern crate failure;

pub mod core;
#[cfg(feature = "cuda")]
pub mod cuda;
pub mod errors;
pub mod imgproc;
pub mod features2d;
pub mod highgui;
pub mod imgcodecs;
pub mod imgproc;
pub mod mat;
pub mod videoio;
pub mod highgui;
pub mod video;
pub mod objdetect;
pub mod features2d;
pub mod text;
#[cfg(feature = "cuda")]
pub mod cuda;
pub mod video;
pub mod videoio;

pub use core::*;
pub use mat::*;

use errors::*;
use failure::Error;
use std::ffi::{CStr, CString};
use std::mem;
use std::os::raw::{c_char, c_void};
use std::path::Path;
use failure::Error;
use errors::*;

extern "C" {
fn c_drop(value: *mut c_void);
Expand Down Expand Up @@ -159,9 +159,7 @@ unsafe fn unpack<T: NestedVec, U, F>(v: &CVec<T>, mut f: F) -> Vec<U>
where
F: FnMut(&T) -> U,
{
(0..v.size)
.map(|i| f(&*v.array.offset(i as isize)))
.collect()
(0..v.size).map(|i| f(&*v.array.offset(i as isize))).collect()
}

pub(crate) trait Unpack {
Expand Down Expand Up @@ -226,9 +224,7 @@ impl Unpack for CDisposableString {
type Out = String;

fn unpack(&self) -> Self::Out {
unsafe { CStr::from_ptr(self.value) }
.to_string_lossy()
.into_owned()
unsafe { CStr::from_ptr(self.value) }.to_string_lossy().into_owned()
}
}

Expand Down
Loading

0 comments on commit 4637295

Please sign in to comment.