函数调用如下所示,cv2.rectangle的参数依次是图像、左上角坐标、右上角坐标、颜色、线条粗细;cv2.circle的参数依次是图像、中心坐标、半径、颜色、线条粗细。其中线条粗细设置为-1时,则填充满整个图形。
image = cv2.rectangle(img,(f_xmin,f_ymin),(f_xmax,f_ymax),(0,0,255),3)
image = cv2.circle(image, center_coordinates, radius, color, thickness)
import os
import cv2
images = os.listdir('images/')
print(images)
img = cv2.imread('images/'+images[0])
print(img.shape)
# fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')#.avi格式
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')#.mp4格式
videowrite = cv2.VideoWriter('test.mp4',fourcc,10,(640,480))
for i in images:
imgname = 'images/'+i
img = cv2.imread(imgname)
img = cv2.resize(img, (640,480))
# print(img.shape)
videowrite.write(img)
print(imgname)
videowrite.release()
print('end!')
def cv_imread(filePath):
cv_img=cv2.imdecode(np.fromfile(filePath,dtype=np.uint8),-1)
cv_img = cv2.cvtColor(cv_img, cv2.COLOR_RGB2BGR)
return cv_img
cv2.imencode('.png', img_array)[1].tofile(save_path)
#将一维灰度图像扩展到三维
image= np.expand_dims(imagel,axis=2).repeat(3,axis=2).astype(np.uint8)
heat_image = cv2.applyColorMap(depth_image, cv2.COLORMAP_JET)
报错内容为:window.cpp:1274: error: (-2:Unspecified error) The function is not implemented.
Traceback (most recent call last):
File “/home/data/PJS/test_bed/img_show.py”, line 18, in
cv2.imshow(‘img’, img)
cv2.error: OpenCV(4.5.3) /tmp/pip-req-build-9gwtlx3c/opencv/modules/highgui/src/window.cpp:1274: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function ‘cvShowImage’
解决方法:
import cv2
print(cv2.__file__)
#删除打印出来的cv2文件夹即可
#如果不行,卸载并重新安装opencv-python就可以了
更多三维、二维感知算法和金融量化分析算法请关注“乐乐感知学堂”微信公众号,并将持续进行更新。