gali8 / Tesseract-OCR-iOS

Tesseract OCR iOS is a Framework for iOS7+, compiled also for armv7s and arm64.
http://www.nexor.it
MIT License
4.22k stars 949 forks source link

Swift setting rect not working #148

Closed galli-leo closed 9 years ago

galli-leo commented 9 years ago

I wanted to set a rect on the tesseract as follows:

var tesseract:Tesseract = Tesseract(language: "deu")
tesseract.delegate = self;
tesseract.setVariableValue("01234567890", forKey: "tessedit_char_whitelist");
tesseract.rect = CGRectMake(20, 20, 100, 150);
tesseract.image = theImage;
tesseract.recognize();

NSLog("%@", tesseract.recognizedText);

But it does not work. When using the debugger it says the rect is 0,0,0,0 and the result is either a one or two letter combination which does not in anyway correspond to the image.

galli-leo commented 9 years ago

Sorry it is my fault. Strangely when applying filters with CIFilters all images rotate by 90°

kevincon commented 9 years ago

What do you mean "now the sentence is repeated"? Are you still running the same code that you mention above? What image are you trying to recognize on? What filters?

In general, please always include a really detailed description of what you're doing to cause the issue you're reporting, because otherwise we can't reproduce the issue ourselves to help you.

kevincon commented 9 years ago

Actually, since this (the result being repeated) seems to be the same issue you describe in #149, I'm going to close this issue and mark it as a duplicate. Please continue this discussion in #149.

galli-leo commented 9 years ago

Sorry I posted the sentence is repeated to the wrong issue. The issue here still persists: tess This is the tesseract variable after recognizing or after setting the rect

galli-leo commented 9 years ago

actually although it does not say the rect is there it still works.

kevincon commented 9 years ago

One thing you should know is that any time you set the image, we reset the rect member variable of G8Tesseract to be a rectangle with origin (0,0) and width and height to match the new image. However, we still actually call the upstream Tesseract setRectangle function even if you set the rectangle BEFORE setting the image, so that explains why it still works. But you might want to still set the rectangle AFTER you've set the image, because that will make sure that the rect member variable of G8Tesseract reflects the correct rectangle that Tesseract will be looking at.

Now, on to the issue of the debugger not showing the rectangle that you've set. I was able to reproduce this in Swift, and honestly I can't explain why the debugger does not show the rectangle that was set. I even tried what I mention in the previous paragraph (setting the rect after setting the image), and it's still all zeroes.

However, when I look at setting the rectangle in the Template Framework Project (which is an Objective-C demo app included in this repo), I see the rectangle being set correctly:

screen shot 2015-02-18 at 10 31 10 am

So long story short, don't worry that you're not seeing the rectangle being set in Swift because I think this is a bug in Apple's Swift debugger since it does show up correctly in Objective-C.