Mac-pycharm install cv2

1. .. upper left corner of the Preferences .      

2. Click the plus sign at the mouse location as shown in the figure

3. Enter opencv in the search box, then select opencv-python, and then click Install Package in the lower left corner

Enter numpy in the search box, select numpy, and then install in the lower left corner

4. Enter a simple demo and run (code is given below)

import numpy as np
import cv2

path = 'picture/dragon.jpeg'
new_path = 'picture/dragon_grey.jpeg'

img = cv2.imread(path, 0)
cv2.imshow(path, img)

k = cv2.waitKey(0)

if k == 27:# wait for ESC key to exit
    cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
    cv2.imwrite(new_path, img)
    cv2.destroyAllWindows()

Guess you like

Origin blog.csdn.net/qq_39429779/article/details/108685190