iOS:Retrieve rectangle shaped image from the background image

前端 未结 2 1928
失恋的感觉
失恋的感觉 2020-12-01 15:37

I am working on an implementation where I have a rectangle shaped image in an big background image. I am trying to programmatically retrieve the rectangle shaped image from

2条回答
  •  我在风中等你
    2020-12-01 15:56

    Here is a partial answer. It is not complete because I am attempting to do the exact same thing and experiencing huge difficulties every step of the way. My knowledge is quite strong on objective-c but really weak on C++

    You should read this guide to wrapping c++

    And everything on Ievgen Khvedchenia's Computer Vision Talks blog, especially the openCV tutorial. Ievgen has also posted an amazingly complete project on github to go with the tutorial.

    Having said that, I am still having a lot of trouble getting openCV to compile and run smoothly.

    For example, Ievgen's tutorial runs fine as a finished project, but if I try to recreate it from scratch I get the same openCV compile errors that have been plaguing me all along. It's probably my poor understanding of C++ and it's integration with obj-C.

    Regarding squares.cpp

    What you need to do

    • remove int main(int /*argc*/, char** /*argv*/) from squares.cpp
    • remove imshow(wndname, image); from drawSquares (obj-c will do the drawing)
    • create a header file squares.h
    • make one or two public functions in the header file which you can call from obj-c (or from an obj-c/c++ wrapper)

    Here is what I have so far...

    class squares
    {
    public:
             static cv::Mat& findSquares( const cv::Mat& image, cv::vector >& squares );
             static cv::Mat& drawSquares( cv::Mat& image, const cv::vector >& squares );
    
    };
    

    you should be able to reduce this to a single method, say processSquares with one input cv::Mat& image and one return cv::Mat& image. That method would declare squares and call findSquares and drawSquares within the .cpp file.

    The wrapper will take an input UIImage, convert it to cv::Mat image, call processSquares with that input, and get a result cv::Mat image. That result it will convert back to NSImage and pass back to the objc calling function.

    SO that's a neat sketch of what we need to do, I will try and expand this answer once I've actually managed to do any of it!

提交回复
热议问题