【Python】 package之imutils介绍

安装:

pip install imutils

注:安装该包依赖于NumPy、Opencv和matplotlib

函数介绍:

该包中主要5个函数,比使用直接使用Opencv库更加的便利用户

Translation
example:

# translate the image x=25 pixels to the right and y = 75 pixels up

translated = imutils.translate(im,25,-75)

Rotation

功能:可以使图片旋转一定的角度

example:

#loop over the angles to rotate the image

for angle in xrange(0,360,90): 

      #rotate the image and display it

      rotated_im = imutils.rotate(im,angle=angle)

      cv2.imshow("Angle=%d" % (angle),rotated)

Resizing

功能:resize函数可以在保证原有图片的长宽比的条件下对图片进行缩放。同时,该函数也提供width和height参数,可以将图片变换为任意长宽比的图片。

example:

# loop over varying widths to resize the image to

for width in (400,300,200,100):

          # resize the image and display it

          resized = imutils.resize(im,width=width)

          cv2.imshow("Width=%dpx"%(width),resized)

Skeletonization

功能:假设图片是白图像黑背景,该函数可以画出图片上图像的结构。函数包含两个必须参数,第一个是单通道图片,第二个参数是size,size is the size of the structuring element kernel.还有一个可选参数structuring,默认为cv2.MORPH_RECT

#skeletonize the image

gray = cv2.cvtColor(logo,cv2.COLOR_BGR2GRAY)

skeleton = imutils.skeletonize(gray,size=(3,3))

cv2.imshow("Skeleton",skeletyon)

Displaying with Matplotlib

功能:将图片从Opencv的表示形式转换为matplotlib模块可显示的形式。

注:Opencv默认用BGR格式打开图片,motplotib用RGB格式打开图片

example:

im = cv2.imread(example.png)

# INCORRECT:show the image without converting color spaces

plt.figure("Incorrect")

plt.imshow(im)

# Correct:covert color spaces before using plt.imshow

plt.figure("Correct")

plt.imshow(imutils.opencv2matplotlib(im))

plt.show()
--------------------- 
作者:qq_35536179 
原文:https://blog.csdn.net/qq_35536179/article/details/82666255 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值