Closed richard512 closed 8 years ago
You're in for some debugging :) I'll assume you've tried to ground the provided image files and that is working.
N >= K in function kmeans
: K-means is a clustering algorithm. It's used to guess the lines of text of the image.
K, by convention, is the number of clusters, and N is probably the number of samples. I'm guessing what happened is the number of samples is too low (ys
variable).
https://github.com/goncalopp/simple-ocr-opencv/blob/master/segmentation_aux.py#L63 Bubbling up the code, we can see that line is making the samples be the detected from the segment's top coordinates. Too few samples thus means too few segments (characters) detected.
You need to figure out how many segments you are getting detected. If you didn't get any, or just a couple, the most likely problem is that your image is defeating the segmentation algorithm.
You can try to run just segmentation by itself by removing pipelines stages here: https://github.com/goncalopp/simple-ocr-opencv/blob/7bcd3f15423321c55584b56eb5635be665784bee/segmentation_filters.py#L8 And running the segmenter like so: https://github.com/goncalopp/simple-ocr-opencv/blob/master/ocr.py#L40
Hopefully you've used pdb
before? It's a great tool :)
I hope that helps you getting started. Let me know if you need any help (I'll need the image file and your example.py
to replicate your results
Actually, I'm getting errors when attempting to create grounding for digits1.png, too.
What did you use in order to create digits1.box?
Here's the error while attempting to create grounding for digits1.png:
showing after BlurProcessor (waiting for input)
showing ContourSegmenter contours (waiting for input)
showing image after segmentation by RawContourSegmenter (waiting for input)
showing segments filtered by LargeFilter (waiting for input)
showing segments filtered by SmallFilter (waiting for input)
showing segments filtered by LargeAreaFilter (waiting for input)
showing segments filtered by ContainedFilter (waiting for input)
showing line starts and ends (waiting for input)
showing segments filtered by NearLineFilter (waiting for input)
OpenCV Error: Unspecified error (The search tree must be constructed first using train method) in find_nearest, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/ml/src/knearest.cpp, line 365
Traceback (most recent call last):
File "mkground.py", line 14, in <module>
test_classes, test_segments= ocr.ocr( test_image, show_steps=True )
File "/home/username/simple-ocr-opencv/ocr.py", line 44, in ocr
classes= self.classifier.classify( features )
File "/home/username/simple-ocr-opencv/classification.py", line 61, in classify
retval, result_classes, neigh_resp, dists= self.knn.find_nearest(features, k= 1)
cv2.error: /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/ml/src/knearest.cpp:365: error: (-2) The search tree must be constructed first using train method in function find_nearest
What did you use in order to create digits1.box?
Code very similar to the one on issue 2. I've tried and got it working again.
It looks like you're running ocr.ocr()
without calling train()
first?
If you just want to ground, there's no need to call either.
To be clear, the entire machine learning process needs steps in this order:
.ground()
)train()
)ocr.ocr()
)If you're having further problems, please publish your code somewhere so I can take a look
I just found a way to make box files using tesseract:
tesseract digits2.png digits2 batch.nochop makebox
I'm still not sure how to get UserGrounder.ground() inside grounding.py to run because I'm not sure how I'm supposed to supply "segments"
I'm still not sure how to get UserGrounder.ground() inside grounding.py to run because I'm not sure how I'm supposed to supply "segments"
A quick read of the source for ocr()
should help.
I've added example_grounding.py
, please let me know if that helps. Instructions on interactive grounding are written to the stdout
(command line)
Loving the new update. This does exactly what I've been searching for. Thank you.
Forked and added a few things: https://github.com/richard512/simple-ocr-opencv
README update, added a CAPTCHA grounding example, and made a little edit to ContourSegmenter for allowing easier customization of filters.
Happy that you found it useful. I did a quick read - looking good. Feel free to do a pull request once you're happy with it, I'll review it more thoroughly Also, if you're breaking CAPTCHAs with this, please let their users know how bad they are :) Hopefully that'll improve the quality.
Step 1) Tried to change the training image in example.py
Step 2) Bumped into an error
Step 3) Tried the solution issue 2 suggests
Step 4) But an error occurred: