I found that page about OCR using Tesseract on OpenCV 3.1. The problem is that given links include examples with older OpenCV versions. Is there any up to date example of usage of OCR Tesseract? and How can I told this to OpenCV authority?
The sample code below is unfortunately in Python with the text module/opencv_contrib of OpenCV 3.2. I compiled Tesseract 4.0.0alpha with OpenCV 3.2.0 binding to make it works few months ago. Hope this could be a reference for your C++ implementation.
# para: tessdata path, language, whitelist, psm, oem
tesser = cv2.text.OCRTesseract_create('C:/Program Files/Tesseract 4.0.0/tessdata/','eng',
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',11,3)
retval = tesser.run(processed_image, 0) # ' return string type
As far as I know, the Text module doesn't work well in OpenCV 3.0/3.1. Would suggest to use 3.2.0 to avoid any possible issue on earlier 3.x versions.
Related
I am using c++ to load and run tensorflow graph. The tensorflow version is 2.1 cpu. I have included necessary header files and the libary _pywrap_tensorflow_internal.lib
I use
unique_ptr<tensorflow::Session> session_inception(tensorflow::NewSession(SessionOptions()));
to create a new session. The compiling has no error.
But when I build the executable, there is a link error saying that NewSession is an unresolved external symbol. I guess the function "NewSession" is not in the library file "_pywrap_tensorflow_internal.lib".
How to call NewSession in c++ environment? or maybe using new APIs to run the graph (instead of using session)? Thank you very much.
I assume you're using this code from 2016: https://gist.github.com/kyrs/9adf86366e9e4f04addb which I found by googling for "session_inception". This code predates TensorFlow 2.1 and 2.0 (which was released in September 2019).
The TensorFlow 2.1 documentation does not list any function or type named Session or NewSession - I'm not a TensorFlow user but I think ClientSession is the current type you want.
Here's the sample code from the TensorFlow 2.1 documentation
Scope root = Scope::NewRootScope();
auto a = Placeholder(root, DT_INT32);
auto c = Add(root, a, {41});
ClientSession session(root);
std::vector outputs;
Status s = session.Run({ {a, {1}} }, {c}, &outputs);
if (!s.ok()) { ... }
That said, if you want to run this code from March 2016 you should just download the closest version of TensorFlow released around that date, which is version v0.7.1 available here: https://github.com/tensorflow/tensorflow/releases/tag/v0.7.1 - this is probably inadvisable as TensorFlow's documentation website only has documentation for versions released after v1.0
As an aside, I assume you're relatively new to working in C++ because I found this information quickly in a matter of seconds - had you done the same you wouldn't have posted this question to SO. If you are inexperienced working with C++ or TensorFlow then I advise you that it would be a bad idea to go wading around obsolete and unsupported C++ libraries as you'll be SOL if anything goes wrong - and things will go wrong, especially with prelease versions of TensorFlow.
I have been using dlib object detection successfully on mac. Now I want to use it in an iOS app. However, after spending countless hours, dlib object detector always returns zero rectangles.
ifstream fin(dataDir + "/object_detector.svm", ios::binary);
typedef dlib::scan_fhog_pyramid<dlib::pyramid_down<6> > image_scanner_type;
dlib::object_detector<image_scanner_type> detector;
dlib::deserialize(detector, fin);
vector<dlib::rectangle> dets = detector(dlibImage);
To make sure it’s not due to a different image, I am using exact same image for which detector returns 1 hit on mac. I have also printed uchar from part of the image in both mac and iOS, and it’s returning same values. So image data is exactly the same.
Probably dlib library is not built correctly for iOS. I have tried multiple approaches for this. From /example/build dir, below command was invoked.
cmake -G Xcode ..
cmake --build . --config Release
It generated dlib.xcodeproj project in dlib_build dir. I opened the project in xcode, changed architecture to iOS (armv7, arm64) and rebuild the library. This library was linked to my project. I got zero results with this approach. dlib was built in debug mode; I did not get any assertion errors.
Second approach tried was to use dlib/all/source.app in my project. I used all the proprocessing flags that are used by cmake or dlib.xcodeproj project. No errors, but still no matches.
I have compared build settings of my xcode project with examples.xcodeproj generated by cmake and it’s same. Also checked the xcode project from https://github.com/zweigraf/face-landmarking-ios, but no help.
Strange thing is detector takes couple of seconds to process and comes back with zero matches. So it’s doing something. I wish there was a debug logging that I can turn on for the detector.
I am out of ideas. Will appreciate if anyone can help. dlib is a wonderful library, I just wish it would have been easier to work with on iOS.
dlib is working fine on iOS too. Kicking myself for it, but I mixed up the detector instances. The detector on which I called below line was not used for object detection.
dlib::deserialize(detector, fin);
I was just using an empty detector instance, and it was returning 0 detections. By empty detector, I mean it was defined but deserialize method was not invoked. It would have been nice if dlib returned an error or warning, if a detector not loaded with object_detector.svm file is used for detection.
I have observed the same behavior with shape detector too. If sp.dat is not loaded, it silently reports 0 parts detected. Posting this as answer, in case someone else also makes such a silly mistake.
I see that in version 3 of Opencv , "CommandLineParser" is used much ;but I don't get how it works.I am new with programming.can anyone give me some help please?
another question is that , before I was working with Opencv 2 version , and reading image is quite simple by "Imread("file address",type)" but I see that in new version it is mostly done by commandine arguments . what is advantage of this,and how it works exactly?
I am working with Visual studio 2015 on Windows 10
thanks
I ran into an issue getting the standard open CV face detection (facedetect) working. The web cam light comes on but noting happens, the program is launched with a tiny sized window like this:
I am working from an excellent blog post and sample code. Here I what I have done:
Install OpenCV & get OpenCV source
brew tap homebrew/science
brew install --with-tbb opencv
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6/opencv-2.4.6.tar.gz
tar xvzf opencv-2.4.6.tar.gz
Run the facedetect sample with the standard classifier.
cd ~/opencv-2.4.6/samples/c
chmod +x build_all.sh
./build_all.sh
./facedetect --cascade="../../data/haarcascades/haarcascade_frontalface_alt.xml"
I can modify the C++ sample code and recompile and run, but I have no idea what the issue is.
Does anyone have a suggestion?
Update The issue is the image from cvQueryFrame is empty:
IplImage* iplImg = cvQueryFrame( capture );
frame = iplImg;
if( frame.empty() )
{
cout << "FRAME EMPTY\n"; // This is getting logged
break;
}
Update: It works ok when the source is a static image, so the issue is something related to the webcam source.
You can try to localise the problem, did you try to capture an image from the and web cam show it, without running any other operation?
It seems there is a problem capturing image from the web cam via OpenCV, this kind of problems may happen due to hardware, for instance on my friends macbook pro captured image was 320x240 and on mine it was 640x480. My friend just changed a simple configuration from settings of the camera and his problem was solved. Your problem might be something like this.
Or you can try to run face detector just with some images, you need to change the code such that it loads an image from your disk and try to detect face on them. If it doesn't work that way either we can say that your problem is not camera, there is a bigger issue, or if it works we can surely say that the problem is web cam.
EDIT
If you are using IplImage type be sure to get couple more images from the camera, sometimes first image is empty.
This was due to a bug in OpenCV - its been fixed ( bug report here http://code.opencv.org/issues/3156) , but the version in homebrew/science is from before the fix.
You can get install a newer version by editing the brew formula for opencv ( based on this pull request https://github.com/Homebrew/homebrew-science/pull/540 )
edit /usr/local/Library/Formula/opencv.rb , and replace these lines:
url 'http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.6.1/opencv-2.4.6.1.tar.gz'
sha1 'e015bd67218844b38daf3cea8aab505b592a66c0'
with these ones
url 'https://github.com/Itseez/opencv/archive/2.4.7.1.tar.gz'
sha1 'b6b0dd72356822a482ca3a27a7a88145aca6f34c'
Then do
brew remove opencv
brew install opencv
Works on Mavericks (for me at least), should work on Mountain Lion
UPDATE: the version of OpenCV in homebrew/science has now been updated, so this answer is now out of date!
brew upgrade opencv
will make homebrew get the latest version, with fixed webcam capture.
Could it be that there is a bug in OpenCV2.4 highgui for capturing frames from video in windows?
I installed both the precompiled libraries, the ones compiled by me, I can compile everything perfectly and I can run my programs if
they are image based. The problem is only for videos. OpenCV crashes in this function always:
virtual IplImage* retrieveFrame(int)
{
unsigned char* data = 0;
int step=0, width=0, height=0, cn=0;
if(!ffmpegCapture ||
!icvRetrieveFrame_FFMPEG_p(ffmpegCapture,&data,&step,&width,&height,&cn)) <-------CRASHES HERE
return 0;
cvInitImageHeader(&frame, cvSize(width, height), 8, cn);
cvSetData(&frame, data, step);
return &frame;
}
This is inside the class cap_ffmpeg.cpp and is called by VideoCapture.
I tried versions 2.4.2 and 2.4.9. My programes were working finde with opencv2
More information
Windows 7
Build the projects with cmake (important as it could be that cmake is not building/finding the right codecs)
VisualStudio 9 2008
OpenCV 2.4.2
EDIT
It looks like it is actually a bug, so, how can I solve this problem and change my code to be able to read avi files?
As a temporary solution I decided to re-encode the videos so OpenCV doesn't use the ffmpeg. I used VirtualDub with the microsoft video 1 compression, which uses "msvidc32.dll" driver.
It works with all my videos so it is enough by now as I can keep working with OpenCV in windows.
I had similar problem. I downloaded VirtualDub, but it did not open one of my avi video because of its FMP4 encode. So in the end, the solution that solved the problem was to install ffdshow, a decoder for windows. See this link: http://www.moviecodec.com/video-codecs/fmp4-codec-with-virtualdub-45814/
Then I do not need to use VirtualDub anymore to re-encode my video anymore!
if your using x64. Please use opencv_ffmpeg245_64.dll this solves may solve the problem. Or rename opencv_ffmpeg245_64.dll to opencv_ffmpeg245.dll may solve the problem.