介绍图像翻转
图像轮廓排序
图像轮廓排序
这篇文章主要介绍python中OpenCV的知识点示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
图像翻转
使用python的一个包,imutils。使用下面的指令可以安装。
pip install imutils
imutils包的Github地址:https://github.com/jrosebr1/imutils
CSDN镜像:https://codechina.csdn.net/mirrors/jrosebr1/imutils
可以在上面这个地址里面学习更多的使用方式。
import cv2 import imutils & # 39;& # 39;& # 39; imutils.rotate 第一个参数是翻转的图像,第二个参数的翻转角度 函数还提供翻转中心的设置,但默认就是中心翻转。 & # 39;& # 39;& # 39; 时间=vc cv2.VideoCapture (0) if vc.isOpened (): ,,国旗,frame =, vc.read () img 才能=,imutils.rotate(框架,,180),,#,图像翻转, cv2.imshow才能(“frame",, img) 其他: flag 才能=False while 国旗: ,,国旗,frame =, vc.read () if 才能;frame  is 没有: ,才能打破 if 才能;flag  is 如此: ,,,img =, imutils.rotate(帧,180,),,#,图像翻转 ,,,cv2.imshow (“frame",, img) ,,,if cv2.waitKey(10),==, 27日: ,,,,,休息 vc.release () cv2.destroyAllWindows ()
这样写的话,最后的输出图像就是翻转180度的。
imutils包里还有其他好用的函数,调整,4点角度变换,排序轮廓等等。
图像轮廓排序
这个效果同样也是依靠imutils包完成。
得到imutils import 轮廓 import cv2 & # 39;& # 39;& # 39; contours.sort_contours 可选排序方式:“left-to-right",,“right-to-left",,“top-to-bottom",,“bottom-to-top" 返回值为轮廓和外接矩形 contours.label_contour 轮廓包内自带的画轮廓的函数,可以直接用,然后可以在图片上标出轮廓序号 也可以直接使用cv2.drawContours直接画轮廓 & # 39;& # 39;& # 39; 时间=img cv2.imread (r" D: \ opencv-workspace \ Opencv \ test17——VScode \ shapes.png") 时间=draw_img img.copy () 时间=img_rect img.copy () 时间=gray cv2.cvtColor (img, cv2.COLOR_BGR2GRAY) img =, cv2.Canny(灰色,10日,20),,#,精明的边缘检测 碳纳米管,hierarchy =, cv2.findContours (img, cv2.RETR_EXTERNAL,, cv2.CHAIN_APPROX_NONE),, #,获得轮廓 (碳纳米管,boundingBoxes),=, contours.sort_contours(碳纳米管,“top-to-bottom"),, #,对轮廓进行排序处理 for (我,,c),拷贝列举(碳纳米管): sortedImage 才能=,contours.label_contour (c draw_img,,,,我,,颜色=(240,0,159))=#,img_out cv2.drawContours (draw_img,碳纳米管,,1,,(0,240,,159),,2) #,根据boundingBoxes画外接矩形 for (w, x,, y,, h),拷贝boundingBoxes: img_rect 才能=,cv2.rectangle (img_rect,, (x, y), (x + w,, y + h),, (240,, 0, 159,),, 2) cv2.imshow (“top-to-bottom", sortedImage) cv2.imshow (“rect", img_rect) cv2.waitKey (0) cv2.destroyAllWindows ()
这样写的话,最后的输出图像就是翻转180度的。
imutils包里还有其他好用的函数,调整,4点角度变换,排序轮廓等等。
图像轮廓排序
这个效果同样也是依靠imutils包完成。
得到imutils import 轮廓 import cv2 & # 39;& # 39;& # 39; contours.sort_contours 可选排序方式:“left-to-right",,“right-to-left",,“top-to-bottom",,“bottom-to-top" 返回值为轮廓和外接矩形 contours.label_contour 轮廓包内自带的画轮廓的函数,可以直接用,然后可以在图片上标出轮廓序号 也可以直接使用cv2.drawContours直接画轮廓 & # 39;& # 39;& # 39; 时间=img cv2.imread (r" D: \ opencv-workspace \ Opencv \ test17——VScode \ shapes.png") 时间=draw_img img.copy () 时间=img_rect img.copy () 时间=gray cv2.cvtColor (img, cv2.COLOR_BGR2GRAY) img =, cv2.Canny(灰色,10日,20),,#,精明的边缘检测 碳纳米管,hierarchy =, cv2.findContours (img, cv2.RETR_EXTERNAL,, cv2.CHAIN_APPROX_NONE),, #,获得轮廓 (碳纳米管,boundingBoxes),=, contours.sort_contours(碳纳米管,“top-to-bottom"),, #,对轮廓进行排序处理 for (我,,c),拷贝列举(碳纳米管): sortedImage 才能=,contours.label_contour (c draw_img,,,,我,,颜色=(240,0,159))=#,img_out cv2.drawContours (draw_img,碳纳米管,,1,,(0,240,,159),,2) #,根据boundingBoxes画外接矩形 for (w, x,, y,, h),拷贝boundingBoxes: img_rect 才能=,cv2.rectangle (img_rect,, (x, y), (x + w,, y + h),, (240,, 0, 159,),, 2) cv2.imshow (“top-to-bottom", sortedImage) cv2.imshow (“rect", img_rect) cv2.waitKey (0) null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null null nullpython中OpenCV的知识点示例