opencv 爬坑指南
- 路径问题:
import cv2
img = cv2.imread("C:/Users/夏戈/Desktop/1.bmp")
cv2.imshow("image",img)
cv2.waitKey(0)
cv2.destroyAllWindows()
报错error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow’
(1)将"“改成”/"
(2)路径中不能出现中文
- cv2.flip():
img = cv2.imread("C:/Users/myJupyter/pic/2.jpg")
dst_img_1 = cv2.flip(img,1)#垂直翻转(左右)
dst_img_2 = cv2.flip(img,0)#水平翻(上下)
dst_img_3 = cv2.flip(img,-1)#水平垂直翻转
cv2.imshow('11',dst_img)
cv2.imshow('22',dst_img_2)
cv2.imshow('33',dst_img_3)
cv2.waitKey(0)
cv2.destroyAllWindows()
参考链接:https://blog.csdn.net/jningwei/article/details/78753607
- cv2.transpose(scr):
img = cv2.imread("C:/Users/myJupyter/pic/2.jpg")
dst_img = cv2.transpose(img)#逆时针旋转90度
cv2.imshow('11',dst_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
- cv2.fillConvexPoly():函数可以用来填充凸多边形,只需要提供凸多边形的顶点即可。
import matplotlib.pyplot as plt
import numpy as np
img = np.zeros((1080, 1920, 3))
triangle = np.array([[0, 0], [1500, 800], [500, 400]])
cv2.fillConvexPoly(img, triangle, (255, 255, 255))
plt.imshow(img)
plt.show()
- cv2.circle(img, center, radius, color, thickness, lineType=8, shift=0)
img:原图,center:圆圈的中心坐标;radius:圆圈的半径;color:圆圈的颜色;thickness:圆形轮廓的粗细(如果为正),负厚度表示要绘制实心圆;lineType: 圆边界的类型;
shift:中心坐标和半径值中的小数位数。