ncoudray / DeepPATH

Classification of Lung cancer slide images using deep-learning
489 stars 210 forks source link

Questions about cv2.findContours() #136

Closed Gaodelike closed 1 year ago

Gaodelike commented 1 year ago

Hi Nicolas, When running the script 0f_HeatMap_nClasses_Overall.py, an error occurred:

Traceback (most recent call last):
  File "03_postprocessing/0f_HeatMap_nClasses_Overall.py", line 883, in <module>
    main()
  File "03_postprocessing/0f_HeatMap_nClasses_Overall.py", line 791, in main
    skip = saveMap(HeatMap_divider, HeatMap_0, WholeSlide_0, slide, NewSlide, dir_name, HeatMap_bin)
  File "03_postprocessing/0f_HeatMap_nClasses_Overall.py", line 549, in saveMap
    fields2, rows2, TumorArea2 = Get_Binary_stats(ImStat1 + ImStat2)
  File "03_postprocessing/0f_HeatMap_nClasses_Overall.py", line 298, in Get_Binary_stats
    a, contours,b = cv2.findContours(b_tmp,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
ValueError: not enough values to unpack (expected 3, got 2)

Then I checked the source code and found that the cv2.findContours() function has undergone some changes in opencv3 and 4. In opencv-python-4.4.0.42, the return value of this function is only two, and in the code of the script it seems Three return values are set, so I wonder if this script has not been transplanted from opencv3 to 4.

So I deleted the first return value a of cv2.findContours() in line 297 of the code:

# before:
a,contours,b=   cv2.findContours(b_tmp,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
# now:
contours,b=   cv2.findContours(b_tmp,cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

After modification, it runs successfully and produces results, but I'm not familiar with opencv, so I want to confirm this problem, looking forward to your reply.

All the best.

ncoudray commented 1 year ago

Hi -

Indeed, the code has been conceived with the library versions in the yml files on the main page of github.

From their website (https://docs.opencv.org/4.0.0/d4/d73/tutorial_py_contours_begin.html), it looks indeed like the first output has been dropped in v 4.

Best