安装:

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()

 

技术
今日推荐
PPT
阅读数 121
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信