Opencv by default uses highGUI to display pictures, run with the command line, can be displayed normally

cv.namedWindow("Image")
cv.imshow("Image",img)Copy the code

Jupyter is no reaction

In this paper, the environment

import sys
import cv2
print("Python version: % s"% sys.version)
print(Opencv version: "% s"% cv2.__version__)Copy the code

The output

Python version: 3.5.3 | Continuum Analytics, Inc. | (default, May 15, 2017, 10:43:23) [MSC v. 1900 64 - bit (AMD64)] opencv version: 3.2.0Copy the code

Install opencv

If Anaconda is used, open the Anaconda Prompt and activate PYTHon35 to switch to the appropriate Python environment

pip install --upgrade setuptools
pip install numpy Matplotlib
pip install opencv-pythonCopy the code

In jupyter, we run the next demo code of this blog post, but no response

After some Google, it has been solved and is now sorted out as follows

Jupyter Displays OpencV pictures

Take the Lenna picture


import cv2
from matplotlib import pyplot as plt

img = cv2.imread('lenna1.png')

show_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) 

plt.imshow(show_img)
plt.show()Copy the code

See Quickie: Mix up OpenCV and Jupyter (iPython Notebook) and official Using Matplotlib

Opencv reads network images

%matplotlib inline
import numpy as np
import cv2
from matplotlib import pyplot as plt
import urllib.request as ul

data = None

try:

    data = ul.urlopen('http://www.mupin.it/wp-content/uploads/2012/06/lenna1.png').read()

except Exception as e:

    print("Could not download the image: %s " %( e.message))

else:
    data =  np.fromstring(data, np.uint8)
    img_data =  cv2.imdecode(data, cv2.IMREAD_COLOR )
    img_data = cv2.cvtColor(img_data, cv2.COLOR_BGR2RGB)
    plt.imshow(img_data)
    plt.show()Copy the code

This example uses python:3.5.3 and OpencV :3.2.0, Cv2. CV_LOAD_IMAGE_COLOR does not exist in Opencv3. x; cv2.IMREAD_COLOR does not exist in Opencv3. x

Most of the code is referenced from Quickie: Grab an Image from the Web with urllib2 and OpenCV

OpenCV introductory tutorial

Blog anjia. Ml / 2017/07/16 /… The nuggets juejin. Cn/post / 684490… Jane books www.jianshu.com/p/69af8b1dc…