OpenCV cv2.imshow() function keep running in Jupyter Notebook using python 3 - python

I just start to learn OpenCV in Python and mainly use jupyter notebook. The sample I learnt comes from course https://pythonprogramming.net/loading-images-python-opencv-tutorial/
I load an image using cv2.imread() and want to show it up using cv2.imshow(). The image was shown successfully but the program keeps running and can't be interrupted.
May I know why?
Please check following codes:
import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
img=cv2.imread('sample1.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows() # This part of code keeps running.

Related

Keras UNet: AttributeError

I am currently trying to run a U-Net model in Keras, using PyCharm and Anaconda on Windows. My first attempts kept on working well. However, now I'm getting an error when I try to acces keras:
My imports:
from unet_model import multi_unet_model
from keras.utils import normalize
import os
import glob
import cv2
import numpy as np
from matplotlib import pyplot as plt
The error:
AttributeError: module 'tensorflow.python.client.pywrap_tf_session' has no attribute 'cxx_version'
Maybe one of you encountered the same problem and can give me a hint how to solve it.
The problem occured after trying to move the model from cpu to gpu. Now the model can't be processed at all. Maybe I changed some references without knowing it.

Jupyter Notebook Encoding Issue With Specific Kernel

I have a Jupyter Notebook setup using AWS EMR which runs the notebook on the master node using docker containers.
There are 3 kernels available: (pyspark, python 3, spark)
kernels screenshot
Some simple code for testing the encoding issues below:
using kernel pyspark
%%pretty
import pyspark.sql.functions as F
print("哈哈")
Output is: ??
using kernel python 3:
%matplotlib inline
from matplotlib import pyplot as plt
print("哈哈")
Ouptut is: 哈哈
Anyone has any idea what could be going wrong here?

kernel dead in using pytorch

The kernel crashes when I run a simple code using pytorch (even though it's not used here).
import numpy as np
import matplotlib.pyplot as plt
import torch
x=np.arange(0,10,0.1)
plt.plot(x,np.sin(x))
plt.show()
When I run this code on Jupyter, it shows the kernel is dead. When I run it on Visual Code, it shows:
Canceled future for execute_request message before replies were done
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.
How to resolve this issue. The torch package is supposed to be used later.
This problem has been solved by updating the numpy and matplotlib packages. These packages were installed just one year ago, though.

I'm trying to import but jupyter notebook dies

from skimage import io
I'm trying to import but jupyter notebook dies
the kernel appears to have died. it will restart automatically.
try google colab instead, I had same issue and it got resolved with google colab.

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.

Categories

Resources