mirror of
https://github.com/CCExtractor/ccextractor.git
synced 2026-04-14 01:54:01 +00:00
Terrible OCR results with Channel 5 (UK) #387
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cfsmp3 on GitHub (Feb 13, 2018).
(current master, pre 0.87)
This file (but well, all of channel 5)
https://drive.google.com/open?id=1Etq-pv5G3jGqVhhRl7cNrfuw4gaKkLoV
Produces terrible results in the OCR, even though the bitmaps seem normal. What's going on?
@cfsmp3 commented on GitHub (Feb 13, 2018):
GSOC qualification: 5 points
@harrynull commented on GitHub (Feb 13, 2018):
The problem is in
quantize_map(alpha, palette, rect->data[0], size, 3, rect->nb_colors);(ocr.c:773).Comment this line out can solve the problem.
With

quantize_map:Without

quantize_map:By the way, for reference of my own and maybe someone who wants to look into OCR, I suggest to add
save_spupng("debug.png", indata, w, h, palette, alpha, 16);somewhere at the beginning of theocr_bitmapso that it's easier to know what the raw image looks like without any further process. I don't want to open a PR to add just a line for debugging though.@Abhinav95 commented on GitHub (Feb 13, 2018):
This is pretty interesting. The quantize_map() function in itself was important (from my discussions with @anshul1912 ) in order to improve the DVB results. What the function does essentially is to kind of 'binarize' the input image into text and non text regions and ignore the gradient grayscale values at the edge of the text and non text regions. With these particular set of subtitles, it seems like the binarization process is leading to some unwanted noisy artifacts around the text regions, which is throwing off the OCR results. This could probably be solved by an additional filtering step to remove the 'salt noise' present in the current images.
@thealphadollar commented on GitHub (Feb 13, 2018):
@Abhinav95 I think I can look in this issue (with your help) if you don't mind :)
@Abhinav95 commented on GitHub (Feb 13, 2018):
@thealphadollar Go right ahead :)
@cfsmp3 commented on GitHub (Feb 14, 2018):
Things we could do:
@thealphadollar commented on GitHub (Feb 15, 2018):
@cfsmp3 For now, I'll be trying to incorporate the mentioned library. Let's hope something good turns up :)
@thealphadollar commented on GitHub (Feb 15, 2018):
TL;DR: I do not think it would be a wise decision to use libimagequant library. I also tried with a library called exoquant but it doesn't seem to be compatible with libpng decoding method of PNG files. I will search a little more and see if I can find some better library, otherwise resort to making quantize_map() optional.
Using libimagequant makes the process highly inefficient as can be seen in the below screenshot. This is an implementation of the processes involved but they were not entirely implemented into the OCR system. Nevertheless, full implementation has two issues which are elaborated after the screenshot.
Code after full implementation:
I looked on the web and it seemed like that is a problem with the latest version but even downgrading the version did not make any difference.
Also, after partial implementation I could still see the "salt noise" (less than quantize_map() though) in the raw_image which might be an indication of the fact that even after full implementation we could still be left with those errors which are there in the current function.
Hence I think it's better to give quantization as an option (though it increases the argument count... sadly :( )
@Abhinav95 Please see if I'm wrong somewhere, and suggest if there's a better way to go about this :)
@adarshshukla19 commented on GitHub (Feb 23, 2018):
@cfsmp3
I ran it on my tesseract and it ran just fine.
https://drive.google.com/open?id=1zf-Gb-v_vgMXXbQ0bgeC_1FYPCan-Qg2
@amitdo commented on GitHub (Feb 23, 2018):
https://github.com/DanBloomberg/leptonica/search?quant
@cfsmp3 commented on GitHub (Feb 23, 2018):
@adarshshukla19 that link is not public
@adarshshukla19 commented on GitHub (Feb 26, 2018):
So are you guys working further on the project or not and are all the
issues resolved?
Regards.
Adarsh
On Sat, Feb 24, 2018 at 1:03 AM, Carlos Fernandez Sanz <
notifications@github.com> wrote:
@thealphadollar commented on GitHub (Feb 26, 2018):
I'll be working on adding one more quantisation option, probably from the
leptonica library since we already use it.
One small addition was done a while back which reduces the number of
colours in the colour palette and improves the output slightly.
On 26-Feb-2018 11:08 AM, "Adarsh SHUKLA" notifications@github.com wrote:
@cfsmp3 commented on GitHub (Feb 26, 2018):
@adarshshukla19 Issues are not yet solved, so yes, we're definitely going to continue working on this unless we get really reliable results.
@tsmarinov commented on GitHub (Mar 2, 2018):
After the last commit results at my side are good but still have this french channel with terrible output:
./ccextractor -nofc -in=ts -datapid 0x8c3 -out=srt -stdout -nobom -trim -noteletext -codec dvbsub -dvblang fra -ocrlang fra ./merged/franceo.tshere are the matterials: https://goo.gl/kncQUn
@krushanbauva commented on GitHub (Mar 7, 2018):
The salt noise present in the images can be removed by the method of erosion and dilation.
You can refer to this link for more clarity (Sorry for it being highly mathematical in nature😥 ).
You can see the images to get a clear picture of what happens when you apply a proper combination of these filters.
Original image:


Processed image:
You can find the opencv implementation of erosion and dilation filters.
P.S.: I am not very familiar with the codebase or the tesseract API either, so I might take some time to implement it. Though if anyone wants to go ahead, this might help to solve it.
@thealphadollar commented on GitHub (Mar 7, 2018):
@krushanbauva I thought of implementing this but there are certain issues I was facing and hence, will be taking this up when I've little time in hand.
It's mathematically heavy and hence requires a lot of homework to be done and later a lot of testing so nothing breaks.
I need to analyze in depth how we are reading the images. It makes a lot of difference how the images are read and probably the way openCV does it and we do are drastically different though I believe at the basics they will be somewhat similar.
We cannot add openCV directly since that'll be a huge dependency we are not in (very) need of.
You can surely try to implement it, go through codebase and ask doubts. I'll look back into this when I've couple of days of time in hand. I spent around a week on this, so I can support you on the codebase part a bit :)
@krushanbauva commented on GitHub (Mar 7, 2018):
@thealphadollar
@thealphadollar commented on GitHub (Mar 7, 2018):
Sounds amazing :) @krushanbauva
@cfsmp3 commented on GitHub (Mar 8, 2018):
Good luck @krushanbauva :-)
@cyberdrk commented on GitHub (Mar 8, 2018):
I've got some prior experience in Tesseract and morphological operations, do you guys mind if I join in? :)
@cfsmp3 commented on GitHub (Mar 8, 2018):
You're more than welcome :-)
On Wed, Mar 7, 2018 at 7:17 PM, Dipti Kulkarni notifications@github.com
wrote:
@krushanbauva commented on GitHub (Mar 8, 2018):
@cyberdrk You can go through the articles on the official CCExtractor's page which will get you started with the codebase and also going through the recent PR's give you a lot of intuition as to where things are. 😄
Also, there has been some activity on this part of the code in recent times, so that might help you big time!
P.S.: You are always welcomed to collaborate!! 😋
@amitdo commented on GitHub (Mar 8, 2018):
Tesseract uses Leptonica for image IO and image processing.
@Saiteja31597 commented on GitHub (Mar 27, 2018):
i would like to work on this
@cfsmp3 commented on GitHub (Mar 28, 2018):
No need to ask, just go for it :-)
On Tue, Mar 27, 2018 at 6:17 AM, Saiteja31597 notifications@github.com
wrote:
@thealphadollar commented on GitHub (Apr 1, 2018):
@cyberdrk @krushanbauva Any leads you guys would like to share? I'm starting back my work on this.
@thealphadollar commented on GitHub (Apr 7, 2018):
@cfsmp3 For the past few days I have tried implementing some more libraries (including leptonica) but could not be successful; the problem mostly faced is the incorporation of the libraries without changing the structure of the png file we currently use.
Doing that will be, I believe, inefficient since we are already having three methods which work pretty much perfectly for most of the types of videos.
If I'm not wrong in terms of the compatibility of format, I think we can close the issue since we have already solved the problem this issue raised :)
@cfsmp3 commented on GitHub (Apr 11, 2018):
@thealphadollar png here is an output format, but this is totally unrelated with the OCR, which just takes a bitmap.
@OsamaNabih commented on GitHub (Feb 7, 2020):
What happened to the suggestion of implementing dilation and erosion?
@cfsmp3 commented on GitHub (Feb 7, 2020):
If it's not done no one has sent a PR yet.
Go for it.
On Fri, Feb 7, 2020, 10:16 Osama Nabih notifications@github.com wrote:
@cfsmp3 commented on GitHub (Mar 22, 2023):
Closing - confirmed fixed for the sample on the description. Great job @ziexess !