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

Include text detection example #17

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

JanMarvin
Copy link

@JanMarvin JanMarvin commented Apr 5, 2020

Similar to the face detection I created R functions for text_detection, mostly copying around this sample code.

In a fun coding project I use it to obtain positions of text in images. These positions I can use to crop the larger image with magick to then use tesseracts ocr() on smaller pieces of the original image. (For more preprocessing a magick2opencv() and vice versa function would be nice to have!) [Edit:] A conversion function was added in https://github.com/JanMarvin/opencv/tree/conversion

@jeroen
Copy link
Member

jeroen commented Apr 6, 2020

From the CI, it looks like some of these API's are quite recent and need to be included conditionally to make sure the package can still be built against older versions of libopencv...

@JanMarvin
Copy link
Author

I could have a look if my limited c++ knowledge allows me to fix this. I wasn't really sure if this was something you wanted in opencv after all. Just let me know what you're thinking the next steps should be and I'll see what I can do. After all closing and ignoring the pr is always an option 😉

@jeroen
Copy link
Member

jeroen commented Apr 6, 2020

You would have to do a little bit of research or trial-and-error on when the given headers or API calls were introduced and wrap them in macros like so:

opencv/src/face.cpp

Lines 63 to 65 in 976d4da

#if CV_VERSION_EPOCH < 3
throw std::runtime_error("createBackgroundSubtractorMOG2 requires OpenCV 3 or newer");
#else

@JanMarvin
Copy link
Author

Fixed the build. Requires OpenCV 3.4.3 or newer and a build with DNN enabled

@jeroen
Copy link
Member

jeroen commented Apr 10, 2020

But you're not setting HAVE_OPENCV_DNN anywhere now? So it is disabled for all builds?

@JanMarvin
Copy link
Author

It's defined in opencv.hpp.

Note: Since the c++ part is mostly based on a sample file of a BSD licensed library required for linking with your package anyways, I did not add the BSD header to the package LICENSE.md.

@jeroen
Copy link
Member

jeroen commented Apr 10, 2020

Oh sorry I didn't know HAVE_OPENCV_DNN was defined by the library! So if the library defines that macro, do you still need to check for the version?

@JanMarvin
Copy link
Author

Yeah, didn't realize it at first too, but you do not include it in r-backports on windows

@JanMarvin
Copy link
Author

So if the library defines that macro, do you still need to check for the version?

Yes, the version check is still required. OpenCV 3.4.1 introduced Have_OPENCV_DNN, but
cv::dnn::readNet() was introduced in 3.4.2. Possibly that version is sufficient, but iirc the sample code was included in 3.4.3 and since I didn't want to build 3.4.2 … 😄

@jeroen
Copy link
Member

jeroen commented Apr 10, 2020

OK. I tried to run the example but I can't find the frozen_east_text_detection.pb file? Where does this come from?

@JanMarvin
Copy link
Author

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

Successfully merging this pull request may close these issues.

2 participants