Closed evermeer closed 9 years ago
Hmm, what kinds of images are you passing to tesseract? Like what size, resolution, etc.?
Also this issue might be hard to reproduce just using your code/description above, so would it be possible for you to either send me a copy of your project or provide a little bit more of the code and some sample images so I can help you debug this?
I will ask my client if I'm allowed to send you the project (it's not big, it's a passport OCR of the MRZ bar) could you send me an email to edwin@mirabeau.nl The if it's OK, I can reply with the project attached.
I am getting the image from a GPUImage filter that tries to optimize the picture for the OCR. As you can see the size is 350*1700 The code that gets the picture is this: let snapshot = currentFilterConfiguration.filter.imageFromCurrentFramebuffer() let cropRect:CGRect! = CGRect(x: 350,y: 110,width: 350, height: 1700) let imageRef:CGImageRef! = CGImageCreateWithImageInRect(snapshot.CGImage, cropRect); let croppedImage:UIImage! = UIImage(CGImage: imageRef)! let image :UIImage! = croppedImage.imageRotatedByDegrees(-90.0)
I also tried putting that code within the autoreleasepool.
I sent you an email so you can send me the project if your client says it's okay.
If I get a copy of the project, the first thing I would do is use Instruments to profile the memory usage of the app. Have you tried doing that to see where the memory is being allocated/held to make sure the problem lies with Tesseract and not GPUImage or some other library?
Also can you let me know which version of the library you're using? If you're not using any of the CocoaPods releases, which commit of this repo are you working with (or in other words, how recently did you run pod install
?)?
I can't see anything wrong with the image code you provided, so hopefully the client says it's okay for me to take a look at the project so I can help debug it.
I built your project on my mid-2012 Macbook Pro, OSX 10.10.2 in Xcode 6.2 and ran it on my iPhone 6 running iOS 8.2, and these were my observations:
Are there any differences between your setup and my setup that might explain why everything works okay for me but not for you? Or can you think of any differences in how I'm using the app vs. how you experienced the memory spikes and crashing?
Weird... I have a late 2011 macbook pro and an iPhone 5 with iOS 8.2. And I'm using Xcode 6.2. When I get home I will test it from my iMac and iPhone 5s and 6. When I try the same as you and let it run for 2 minutes, the memory uses goes up steadilly from 70 to 150MB in 2 minutes. But I do have to say that it takes a lot longer when you connect to instruments. On my laptop it took 14 minutes and 33 seconds before it crashed. But there I also see the same memory increase. In instruments I can see that the UIImage.imageRotadedByDegrees went up to using 99MB. so that's not a tesseract thing, but the tesseract.recog_all_words also went up to 40MB. I have just send you a couple of screenshots.
I'll take another look at it tomorrow and see if I can reproduce the memory spikes. I think the 40 MB memory usage for Tesseract is normal, but do you think maybe you're missing a free
call or something for the image rotation?
Also, do you mind posting the screenshots you emailed me here on this thread? That way all of the information for this issue is in one place in case it can help someone else in the future.
Here are the 2 screenshots. I will try to eliminate the rotate memory bug today (it's from an external pod)
Apparently this was not a tesseract issue. this was caused by the image rotating code that I used. When I remove the rotation code the memory usage is steady on 50 to 55MB. The moment that rotated image was used it would not release it's memory
Glad you fixed it!
thanks for your time!
Just to be complete: After searching for suitable code for rotating an image I found out I could best use GPUImage for this (which was already part of my project) The code for rotating an UIImage is: var selectedFilter = GPUImageTransformFilter() selectedFilter.setInputRotation(kGPUImageRotateLeft, atIndex: 0) let image:UIImage = selectedFilter.imageByFilteringImage(croppedImage)
I execute the code below every 2 seconds using a timer. Which each iteration the memory usage grows. Within 2 minutes my app will crash. When i remove the line :'tesseract.image = image' the memory does not grow. Initially I had this code without the autoreleasepool, setting tesseract to nil and clearCache. I also tried initiating the G8Tesseract object only once. None of those did help.