Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vector element not implemented for Point2d #422

Closed
xd009642 opened this issue Feb 10, 2023 · 8 comments
Closed

Vector element not implemented for Point2d #422

xd009642 opened this issue Feb 10, 2023 · 8 comments

Comments

@xd009642
Copy link

So I've been trying to upgrade an internal project to newest opencv-rust to make use of the feature gating to decrease build size. And a few bits of previously working code have now ceased to work. Namely anything which was using Vector::<Point2d>. As far as I can tell there's no issue with this code and it shouldn't have became an error - instead the required trait bounds should have been automatically generated. However, I may be wrong - if so I'd be interested in how to get around this issue without compromising on accuracy.

Below is a sample of error messages:

error[E0599]: the function or associated item `new` exists for struct `Vector<Point_<f64>>`, but its trait bounds were not satisfied
  --> engine/src/foo.rs:82:51
   |
82 |         let mut image_points = Vector::<Point2d>::new();
   |                                                   ^^^ function or associated item cannot be called on `Vector<Point_<f64>>` due to unsatisfied trait bounds
   |
  ::: /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.76.4/src/manual/core/vector.rs:20:1
   |
20 | pub struct Vector<T: VectorElement>
   | ----------------------------------- doesn't satisfy `Vector<Point_<f64>>: VectorExtern<Point_<f64>>`
   |
  ::: /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.76.4/src/manual/core/point.rs:13:1
   |
13 | pub struct Point_<T> {
   | -------------------- doesn't satisfy `Point_<f64>: VectorElement`
   |
   = note: the following trait bounds were not satisfied:
           `Point_<f64>: VectorElement`
           `Vector<Point_<f64>>: VectorExtern<Point_<f64>>`

error[E0277]: the trait bound `Point_<f64>: VectorElement` is not satisfied
  --> engine/src/foo.rs.rs:82:32
   |
82 |         let mut image_points = Vector::<Point2d>::new();
   |                                ^^^^^^^^^^^^^^^^^ the trait `VectorElement` is not implemented for `Point_<f64>`
   |
   = help: the following other types implement trait `VectorElement`:
             Point_<f32>
             Point_<i32>
note: required by a bound in `Vector`
  --> /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.76.4/src/manual/core/vector.rs:20:22
   |
20 | pub struct Vector<T: VectorElement>
   |                      ^^^^^^^^^^^^^ required by this bound in `Vector`

error[E0277]: the trait bound `Vector<Point_<f64>>: VectorExtern<Point_<f64>>` is not satisfied
  --> engine/src/foo.rs.rs:82:32
   |
82 |         let mut image_points = Vector::<Point2d>::new();
   |                                ^^^^^^^^^^^^^^^^^ the trait `VectorExtern<Point_<f64>>` is not implemented for `Vector<Point_<f64>>`
   |
   = help: the following other types implement trait `VectorExtern<T>`:
             <Vector<DMatch> as VectorExtern<DMatch>>
             <Vector<FlannIndexType> as VectorExtern<FlannIndexType>>
             <Vector<GpuMat> as VectorExtern<GpuMat>>
             <Vector<KeyPoint> as VectorExtern<KeyPoint>>
             <Vector<PlatformInfo> as VectorExtern<PlatformInfo>>
             <Vector<Point3_<f32>> as VectorExtern<Point3_<f32>>>
             <Vector<Point3_<f64>> as VectorExtern<Point3_<f64>>>
             <Vector<Point3_<i32>> as VectorExtern<Point3_<i32>>>
           and 27 others
note: required by a bound in `Vector`
  --> /home/daniel/.cargo/registry/src/github.com-1ecc6299db9ec823/opencv-0.76.4/src/manual/core/vector.rs:22:8
   |
22 |     Self: VectorExtern<T>,
   |           ^^^^^^^^^^^^^^^ required by this bound in `Vector`

Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
@xd009642
Copy link
Author

xd009642 commented Feb 10, 2023

Also not sure if it's related but I get an error building in a dockerfile where it generates this code for core:

	/// ## C++ default parameters
	/// * params: FunctionParams()
	#[inline]
	pub fn copy_mat_and_dump_named_arguments(src: &dyn core::ToInputArray, dst: &mut dyn core::ToOutputArray, params: &core::FunctionParams) -> Result<String> {
		extern_container_arg!(src);
		extern_container_arg!(dst);
		return_send!(via ocvrs_return);
		unsafe { sys::cv_utils_copyMatAndDumpNamedArguments_const__InputArrayR_const__OutputArrayR_const_FunctionParamsR(src.as_raw__InputArray(), dst.as_raw__OutputArray(), params.as_raw_FunctionParams(), ocvrs_return.as_mut_ptr()) };
		return_receive!(unsafe ocvrs_return => ret);
		let ret = ret.into_result()?;
		let ret = unsafe { String::opencv_from_extern(ret) };
		Ok(ret)
	}

Which results in this error:

error[E0412]: cannot find type `FunctionParams` in module `core`
    --> /server/target/release/build/opencv-40047abbaa18fde0/out/opencv/core.rs:7873:123
     |
7873 | ...dst: &mut dyn core::ToOutputArray, params: &core::FunctionParams) -> Result<String> {
     |                                                      ^^^^^^^^^^^^^^ not found in `core`

Docker file grabs and builds opencv like this which I'm working on fixing as I really do not like the "4.x" archive download:

# opencv install
RUN mkdir opencv && cd opencv \
    && apt update && apt install -y cmake g++ unzip libclang-6.0-dev \
    && wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip \ 
    && unzip opencv.zip \
    && mkdir -p build && cd build \
    && cmake -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_apps=OFF -DBUILD_LIST=calib3d,core  ../opencv-4.x \
    && cmake --build . \
    && make install

EDIT moving the wget to download 4.7 fixed that issue and now it's just the vector issue. I'm also rolling back to earlier version of rust crate to try and see if there's a point it works

@twistedfall
Copy link
Owner

twistedfall commented Feb 12, 2023

Yeah, the FunctionParams error is likely stems from the fact that you're using development build on 4.x branch, I'll check it out as we will most probably have to face it in the future when there is a new release in 4.x branch.

Regarding the vector issue I suspect it's because you not building some modules any more. Those Vector<T> bindings are generated as needed and if none of the generated OpenCV functions use Vector<Point2d> then it won't be included. But there is a special manual tweak list that allows to generate those anyway so if you would please tell me why (for which OpenCV function) you need Vector<Point2d> I will tweak the settings.

@xd009642
Copy link
Author

calib3d::solve_pnp_ransac I provide a vec of Point2d

@twistedfall
Copy link
Owner

Can you please check the rel branch and tell me if it solves the problem with Vector<Point2d> for you?

@xd009642
Copy link
Author

Can confirm the rel branch fixes the issue 👍

@twistedfall
Copy link
Owner

I've released v0.77.0 with that fix

@xd009642
Copy link
Author

Awesome thanks ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@twistedfall @xd009642 and others