圖像分析用 OpenCV 與 Skimage,哪一個更好?
點擊上方“小白學(xué)視覺”,選擇加"星標(biāo)"或“置頂”
重磅干貨,第一時間送達(dá)
這兩種算法在它們可以檢測到的和不能檢測到的方面都有其起伏。
OpenCV 是用 C++ 在后端進(jìn)行編程的,并作為一個機(jī)器學(xué)習(xí)包,來分析 Python 中的圖像模式。
Skimage 也稱為 Scikit-Image ,是一個機(jī)器學(xué)習(xí)軟件包,用于圖像預(yù)處理以發(fā)現(xiàn)隱藏模式。
OpenCV 建議在基于服務(wù)器的 notebook 上完成,比如 google colab,或者 google cloud、Azure cloud 甚至 IBM 中的 notebook 擴(kuò)展。
而對于 Skimage 來說,即使是 Jupyter Lab/Notebooks 也能很好地工作,因為它在處理上沒有 OpenCV 那么復(fù)雜。
from skimage import datafrom skimage.feature import Cascadeimport matplotlib.pyplot as pltfrom matplotlib import patches# Load the trained file from the module root.trained_file = data.lbp_frontal_face_cascade_filename()# Initialize the detector cascade.detector = Cascade(trained_file)img = data.astronaut()detected = detector.detect_multi_scale(img=img,scale_factor=1.2,step_ratio=1,min_size=(60, 60),max_size=(90, 500))plt.imshow(img)img_desc = plt.gca()plt.set_cmap('gray')for patch in detected:img_desc.add_patch(patches.Rectangle(patch['r']),patch['width'],patch['height'],fill=False,color='r',linewidth=2))plt.show()

# We have detected a face using Skimage in python# Obtain the segmentation with default 100 regionssegments = slic(img)# Obtain segmented image using label2rgbsegmented_image = label2rgb(segments, img, kind=’avg’)# Detect the faces with multi scale methoddetected = detector.detect_multi_scale(img=segmented_image,scale_factor=1.2,step_ratio=1,min_size=(10, 10), max_size=(1000, 1000))# Show the detected facesshow_detected_face(segmented_image, detected)

因此我們在這里看到了如何使用 python 中的 Skimage 檢測人臉和推斷圖像。
from google.colab import drivedrive.mount('/content/drive')image = cv2.imread(r'/content/drive/MyDrive/12-14-2020-tout.jpg')# check properties of the imageimage.shape# This image has 1333 pxl width, 2000 pxl height and 3 channels(red, green, blue)from google.colab.patches import cv2_imshowcv2_imshow(image)
這里我們使用OpenCV上傳了一張圖片:

eye_detector = cv2.CascadeClassifier('/content/drive/MyDrive/haarcascade_frontalcatface.xml')eye_detections = eye_detector.detectMultiScale(image)eye_detections# detect face with eyes on one of the faceseye_detections = eye_detector.detectMultiScale(image)for (x,y,w,h) in eye_detections:cv2.rectangle(image, (x,y), (x+w, y+h), (0,300,0), 2)cv2_imshow(image)

在這里,我們使用 OpenCV 中的 Hascade 參數(shù)技術(shù)檢測了其中一張人臉,該技術(shù)也可以調(diào)整以檢測所有人臉。
交流群
歡迎加入公眾號讀者群一起和同行交流,目前有SLAM、三維視覺、傳感器、自動駕駛、計算攝影、檢測、分割、識別、醫(yī)學(xué)影像、GAN、算法競賽等微信群(以后會逐漸細(xì)分),請掃描下面微信號加群,備注:”昵稱+學(xué)校/公司+研究方向“,例如:”張三?+?上海交大?+?視覺SLAM“。請按照格式備注,否則不予通過。添加成功后會根據(jù)研究方向邀請進(jìn)入相關(guān)微信群。請勿在群內(nèi)發(fā)送廣告,否則會請出群,謝謝理解~
評論
圖片
表情

