[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
安装:
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()