首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >图像分析用 OpenCV 与 Skimage,哪一个更好?

图像分析用 OpenCV 与 Skimage,哪一个更好?

作者头像
小白学视觉
发布2021-12-13 18:34:36
发布2021-12-13 18:34:36
2K0
举报

这两种算法在它们可以检测到的和不能检测到的方面都有其起伏。

OpenCV 是用 C++ 在后端进行编程的,并作为一个机器学习包,来分析 Python 中的图像模式。

Skimage 也称为 Scikit-Image ,是一个机器学习软件包,用于图像预处理以发现隐藏模式。

两者的最佳平台

OpenCV 建议在基于服务器的 notebook 上完成,比如 google colab,或者 google cloud、Azure cloud 甚至 IBM 中的 notebook 扩展。

而对于 Skimage 来说,即使是 Jupyter Lab/Notebooks 也能很好地工作,因为它在处理上没有 OpenCV 那么复杂。

使用 Skimage 分析面部数据的 Python 代码

代码语言:javascript
复制
from skimage import data
from skimage.feature import Cascade

import matplotlib.pyplot as plt
from 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['c'], patch['r']),
            patch['width'],
            patch['height'],
            fill=False,
            color='r',
            linewidth=2
        )
    )

plt.show()
代码语言:javascript
复制
# We have detected a face using Skimage in python
# Obtain the segmentation with default 100 regions
segments = slic(img)

# Obtain segmented image using label2rgb
segmented_image = label2rgb(segments, img, kind=’avg’)

# Detect the faces with multi scale method
detected = 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 faces
show_detected_face(segmented_image, detected)

因此我们在这里看到了如何使用 python 中的 Skimage 检测人脸和推断图像。

使用 OpenCV 分析数据的 Python 代码

代码语言:javascript
复制
from google.colab import drive
drive.mount('/content/drive')
image = cv2.imread(r'/content/drive/MyDrive/12-14-2020-tout.jpg')
# check properties of the image
image.shape
# This image has 1333 pxl width, 2000 pxl height and 3 channels(red, green, blue)
from google.colab.patches import cv2_imshow
cv2_imshow(image)

这里我们使用OpenCV上传了一张图片:

代码语言:javascript
复制
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 faces
eye_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 参数技术检测了其中一张人脸,该技术也可以调整以检测所有人脸。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-12-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小白学视觉 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 因此我们在这里看到了如何使用 python 中的 Skimage 检测人脸和推断图像。
  • 在这里,我们使用 OpenCV 中的 Hascade 参数技术检测了其中一张人脸,该技术也可以调整以检测所有人脸。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档