!pip install opencv-python
!pip install matplotlib
import cv2
import numpy as np
import matplotlib.pyplot as plt
import glob
from IPython.display import clear_output
以上皆為測試cv2函數能正常使用!
pip install opencv-python==4.5.1.48
這個是為了以下的code去做python的更新,因為detector.detect語法太新,需要用更高的python版本去執行
import cv2
import numpy as np
# Read image
im = cv2.imread("123.jpg", cv2.IMREAD_GRAYSCALE)
# Set up the detector with default parameters.
detector = cv2.SimpleBlobDetector()
# Detect blobs.
keypoints = detector.detect(im)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)