简体   繁体   中英

Kaggle Opencv restarts Notebook

I am using Kaggle Python and I am trying to edit images with OpenCV. I am simply trying to crop the image.I am able to do it with Matplotlib but I want to use OpenCv. When I excecute the code, it does not give me any message and it deletes all variables. It is like restarting the whole kernel. The varialbe img is not created and even variables created previously are deleted. Any idea is very appreciated.

import cv2
img = cv2.imread("/kaggle/input/global-wheat-detection/train/07479da31.jpg")
crop_img = img[715:834, 108:176]
cv2.imshow("cropped", crop_img)
cv2.waitKey(0)

You cannot use cv2.imshow in a Kaggle notebook. It requires a Qt backend which the Kaggle notebook is not set up for which is why your notebook is crashing. In addition, cv2.imshow opens up a separate window which of course the notebook environment is also not set up for. Therefore, you unfortunately cannot use OpenCV windowing or interactive functionality in the notebook. Since Matplotlib is working for you, you need to use that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM