lloydowen8 / place-heatmap-2022

Heatmap visualisation for the r/Place 2022 event
27 stars 2 forks source link

img_paths.append incorrect #6

Closed memmam closed 2 years ago

memmam commented 2 years ago

I get this error when running the code. Using Python 3.9, installed the requirements.txt file, zip file is extracted properly (all folders in zip are together in a folder named final_v1)

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
c:\Users\Ellie\Downloads\place-heatmap-2022-main\heatmap.ipynb Cell 5' in <cell line: 7>()
      [4](vscode-notebook-cell:/c%3A/Users/Ellie/Downloads/place-heatmap-2022-main/heatmap.ipynb#ch0000004?line=3)[     if event == cv2.EVENT_LBUTTONDOWN:
      ]()[5](vscode-notebook-cell:/c%3A/Users/Ellie/Downloads/place-heatmap-2022-main/heatmap.ipynb#ch0000004?line=4)[        print('x = %d, y = %d'%(x, y))
----> ]()[7](vscode-notebook-cell:/c%3A/Users/Ellie/Downloads/place-heatmap-2022-main/heatmap.ipynb#ch0000004?line=6)[ cv2.imshow("image", cv2.imread(img_paths[1000]))
      ]()[8](vscode-notebook-cell:/c%3A/Users/Ellie/Downloads/place-heatmap-2022-main/heatmap.ipynb#ch0000004?line=7)[ cv2.namedWindow('image')
      ]()[9](vscode-notebook-cell:/c%3A/Users/Ellie/Downloads/place-heatmap-2022-main/heatmap.ipynb#ch0000004?line=8)[ cv2.setMouseCallback('image', onMouse)

error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor']()

Edit: A reason for this bug seems to have been identified, see comment below.

Edit 2: More issues have cropped up; diagnosing them now.

Edit 3: one-line fix identified, pull request incoming.

memmam commented 2 years ago

Running this in Google Colab gave me a warning that cv2.imshow is known to crash Jupyter Notebook, and suggested I use a patch Google supplies for Colab called 'cv2_imshow' instead. Since this issue involved a crash when opening the image window, I think this is the issue.

memmam commented 2 years ago

The plot thickens... When I switch to cv2_imshow, I get this:

---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

[<ipython-input-7-7d1e3a69f925>](https://localhost:8080/#) in <module>()
      6 
      7 image = cv2.imread(img_paths[1000])
----> 8 cv2_imshow(image)
      9 cv2.namedWindow('image')
     10 cv2.setMouseCallback('image', onMouse)

[/usr/local/lib/python3.7/dist-packages/google/colab/patches/__init__.py](https://localhost:8080/#) in cv2_imshow(a)
     20       image.
     21   """
---> 22   a = a.clip(0, 255).astype('uint8')
     23   # cv2 stores colors as BGR; convert to RGB
     24   if a.ndim == 3:

AttributeError: 'NoneType' object has no attribute 'clip'

I'm trying to figure it out right now.

memmam commented 2 years ago

ALL ISSUES FIXED, one line change

Replace the following line in the fourth code block:

img_paths.append(os.path.join(f"{image_dir}/{folder}/", filename))

with

img_paths.append(os.path.join(f"{folder}/", filename))

memmam commented 2 years ago

See pull request #7

lloydowen8 commented 2 years ago

Also, I'm not sure the colab cv2_imshow behaviour is going to work like you expect! If I remember correctly it will display the images one after the other in the notebook, and not as a "video" per say. Unfortunately this is a limitation of colab, and show should be set to false.

memmam commented 2 years ago

@lloydowen8 It actually worked fine once I applied the fix in #7, up until the heatmap notebook tried to open and it halted the notebook because of a request to open an X Server window, which Colab doesn't support. I was trying Colab in the off-chance that the problem was with my Python install and not with your code.