D-Alex / ropencv

ffi ruby wrapper for opencv
Other
67 stars 14 forks source link

undefined local variable or method `cv' for OpenCV::Cv::Mat:Class #13

Closed cgat closed 10 years ago

cgat commented 10 years ago

I'm getting this error in ropencv_ruby.rb line 326. Here is an exert from the from the code (within the Mat class):

def self.to_native(obj,context)
    if obj.is_a?(Std::Vector::Cv_Point)
        cv::Mat.new(obj.size,1,cv::CV_32SC2,obj.data,cv::Mat::AUTO_STEP).__obj_ptr__
    elsif obj.is_a?(Std::Vector::Cv_Point2f)
        cv::Mat.new(obj.size,1,cv::CV_32FC2,obj.data,cv::Mat::AUTO_STEP).__obj_ptr__
    elsif obj.is_a?(Std::Vector::Cv_Point3f)
        cv::Mat.new(obj.size,1,cv::CV_32FC3,obj.data,cv::Mat::AUTO_STEP).__obj_ptr__
    elsif obj.is_a?(Std::Vector::Fixnum)
        cv::Mat.new(obj.size,1,cv::CV_32SC1,obj.data,cv::Mat::AUTO_STEP).__obj_ptr__
...

The cv method is not defined in Mat. When I run my app specs, I don't see this issue, but when I run in development mode, I'm getting the error.

I'm doing my best to troubleshoot, but running into walls. From my understanding, the Mat class does not have access to the cv method defined in the grandparent module unless Mat includes the grandparent module, so the error seems reasonable.

As an example:

module A
  def a; :a; end
  class B
    def b; a; end
  end
end

A::B.new().b will fail unless B includes A.

Why this works in my specs is beyond me. Any ideas?

Would you be open to changing references to cv::Mat to self, or more explicitly, OpenCV::Cv::Mat in the above code. I can put together a pull request if you like.

D-Alex commented 10 years ago

Yes, you are absolutely right "cv" should never be called from the scope of OpenCV I pushed a fix to master but please feel welcome to submit any further improvements or fixes.

D-Alex commented 10 years ago

gem was released