910JQK / add-jyutping

OCR 粤拼字幕生成工具
6 stars 0 forks source link

"not enough values to unpack" #1

Open chrisbuckleycode opened 4 years ago

chrisbuckleycode commented 4 years ago

Does this work for current python3 and module versions?

I got the following output when running it. My mp4 is in 720p and the subtitles fall within the default box values:

Traceback (most recent call last): File "./jyutping.py", line 167, in main() File "./jyutping.py", line 146, in main text = extractor.extract(frame) File "/home/user/python/add-jyutping-master/extract.py", line 47, in extract self.cleaned = self.clean_image(img) File "/home/user/python/add-jyutping-master/extract.py", line 112, in clean_image return self.clean_after_crop(cropped) File "/home/user/python/add-jyutping-master/extract.py", line 175, in clean_after_crop img = super().clean_after_crop(cropped) File "/home/user/python/add-jyutping-master/extract.py", line 145, in clean_after_crop img = remove_small_islands(img) File "/home/user/python/add-jyutping-master/extract.py", line 310, in remove_small_islands im2, contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) ValueError: not enough values to unpack (expected 3, got 2)

The file I used was downloaded from YouTube. You can try yourself using y2mate site, I tried multiple videos from the YouTube TVB News channel.

910JQK commented 4 years ago

This problem occurs because of an API change of OpenCV. The function findContours used to return 3 values but returns 2 values now (first value was removed). But it isn't a big problem because the removed first value is not used in the code.

You can try to change code such as

im2, contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
_, contours, hierarchy = cv2.findContours(self.thresholded, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)

into

contours, hierarchy = cv2.findContours(img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours, hierarchy = cv2.findContours(self.thresholded, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)