ogkalu2 / comic-translate

Desktop app for automatically translating comics - BDs, Manga, Manhwa, Fumetti and more in a variety of formats (Image, Pdf, Epub, cbr, cbz, etc) and in multiple languages.
Apache License 2.0
913 stars 84 forks source link

CV2 Error !_src.empty() #120

Open nulleve opened 3 weeks ago

nulleve commented 3 weeks ago

Tested on two different machines, both running AMD CPUs and GPUs. Both machines running Windows 24H2 (26120.1350) Dev Insider Edition.

The following error occurs while running both Automatic and Manual seemingly during the Detect Text Boxes and OCR runtime.

Traceback (most recent call last):
  File "C:\Users\Evelynne\Downloads\comic-translate-main\app\thread_worker.py", line 30, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Evelynne\Downloads\comic-translate-main\pipeline.py", line 186, in batch_process
    blk_list = self.block_detector_cache.detect(image)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Evelynne\Downloads\comic-translate-main\modules\detection.py", line 26, in detect
    combined = self.combine_results(bble_detec_result, txt_seg_result, txt_detect_result)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Evelynne\Downloads\comic-translate-main\modules\detection.py", line 51, in combine_results
    content_bboxes = detect_content_in_bbox(crop)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Evelynne\Downloads\comic-translate-main\modules\detection.py", line 210, in detect_content_in_bbox
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.10.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:196: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

Occasionally it seems to run one time before running the error above, however if it runs it just returns and image similar to the following attached, hopefully this is a simple issue I'm overlooking.

notimp commented 3 weeks ago

https://stackoverflow.com/questions/52676020/imread-returns-none-violating-assertion-src-empty-in-function-cvtcolor-er

try renaming image files? and or image folders. ;) (To exclude special characters.)

(if you need a mass renamer for all image files in a comic, Total commander f.e. is free and comes with one, see: https://github.com/ogkalu2/comic-translate/issues/116 (just for the renaming part, also dont follow to a T, but get the gist... :) ))

If that solves your issue provide a sample of the inital paths/filenames, so devs can try to replicate it and solve the issue properly.

you can also do a

pip list

in cmd and compare opencv-python versions, mine is 4.10.0.84 and the program is working fine with that (share that as well, maybe, if yours differs. :) )

Also for replication purposes maybe upload one of the images this is happening with, so devs can try to replicate the error.

notimp commented 3 weeks ago

You can also do a

pip list -o

to see what your outdated dependencies are. (outdated = good in this instance), here are mine:

dependencies comic transate

If your version numbers match, we can be sure, that the dependencies we use have the same version numbers and dont fail, because some of them might have updated and changed something in its code that devs havent reacted to so far - and that your install failed because of that.

Will not be applicable as a troubleshooting step for years into the future, but since I installed my installation on a windows 11 system just a few days ago (made sure to get python-3.9.13), and everything is working -- currently its an easy way to compare what you have installed, and what a person has installed that has the program running without issues.

Only do that if you have ensured, that your comics file names and paths dont include special characters, that the python coding could get hung up on. (bad coding.)

nulleve commented 3 weeks ago

Thanks for the help, the overflow post seemed possible as the original file names were 20240729104144_21b41baf0e48766c2790b0751dfec250_IMAG01_1.jpg and similar however after changing them around to KoreanTest1.jpg and numbered so-forth the issue still persisted. Moving them straight into the working directory seemed to have no affect either, so testing with verbosity afterwards it seems like the image is accurately being found. (This is the case as well when it does fully complete with the automatic mode; i.e with the bugged black-box images) {3D1CCF79-578B-4FAD-B7BA-21F2ABA3550A}

While my opencv-python version seems to be the proper version; {D06023F6-C295-41E7-B2A6-ECE30DB2707B}

A few of my dependencies were more up to date so I downgraded them to your versions, which also seemed to run into the same persistent error prior. {7A3D81FD-207C-4CD4-9EE6-653C33D285AA}

From the list above, it seems like I am clearly missing several dependencies compared to your image (on two different PCs oddly enough), so I ran through and ran pip install --force-install -v for every package you seemed to have shown above to get the proper versions.

{54567689-A67A-4155-8F6F-9EB17F272A5E}

This seems to have failed as well, which now has me endlessly confused haha, if someone wants to give this a run with the same korean images they are going to be listed here below.

20240311210248_8a5caa95f3e25852f4a35fdca61de9a6_IMAG01_2 20240729104144_21b41baf0e48766c2790b0751dfec250_IMAG01_5

notimp commented 3 weeks ago

Missing dependencies, I wouldnt worry about, I also installed pdf support (see one of the recent tickets in here) and installed the specific nvidia driver packages the install instructions hinted at. Which both arent the bare minimum of what you need.

I'll try to convert your images to english now. Give me a sec.

notimp commented 3 weeks ago

Yeah, I could convert both without issues (i used google vision OCR and google translate to translate the text) (placed both images into "C:\Users\USERNAME\Desktop\test" before converting). Therefore filenames werent the problem, neither were the images.

359338965-70107ae7-f05c-4e54-9072-cd4f5acb115b_translated 359338973-de86df13-a8d1-4552-90b3-2fddac5fcedf_translated

All I can do is to point you to: https://github.com/ogkalu2/comic-translate/issues/113

to see if a reinstall fixes it, if not - wait for an actual dev. :)

(If you havent tried ticking/unticking use GPU in the options, you could try that as well and see if it makes a difference (I doubt it). I'm on an ancient intel system with a nvidia 970 and use gpu support. For me it worked out of the box, I then installed the cuda version of the dependencies the installation steps also nudged me to, they also worked - but that doesnt help you much. :) )

Alexamenus commented 1 week ago

This error is due to to a missing dependency that was not specified in the requirements.txt and or an incompatible versions of python.