Skip to content

Commit

Permalink
loadImage
Browse files Browse the repository at this point in the history
  • Loading branch information
Liulongge committed Nov 30, 2020
1 parent 054b48e commit 882c922
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
34 changes: 21 additions & 13 deletions loadImage.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
import cv2
import numpy as np
image_path = "D:\\image\\lena.jpg"

#### 画框 ####
img = cv2.imread(image_path)
cv2.rectangle(img, (10,10), (200,200), (0, 0, 255), 3)
print("图片\n");
# 展示图片
left_up = (100,100)
right_down = (400,400)
color = (0, 255, 255)
width = 5
cv2.rectangle(img, left_up, right_down, color, width)

#### 展示图片 ####
cv2.namedWindow('custom image', cv2.WINDOW_NORMAL)
cv2.imshow('custom image', img)
cv2.imwrite("F:\\1.jpg",img)
cv2.waitKey(0)
cv2.destroyAllWindows()

#### 将图片保存为视频 ####
img_input_path = 'D:\\image\\'#这里写你的文件夹路径,比如:/home/youname/data/img/,注意最后一个文件夹要有斜杠
video_out_path = 'F:\\3.mp4'
vedio_fps = 30 #保存视频的FPS,可以适当调整
video_size=(512,512)

import cv2

img_root = 'F:\\test\\'#这里写你的文件夹路径,比如:/home/youname/data/img/,注意最后一个文件夹要有斜杠
fps = 30 #保存视频的FPS,可以适当调整
size=(960,544)
#可以用(*'DVIX')或(*'X264'),如果都不行先装ffmepg: sudo apt-get install ffmepg
fourcc = cv2.VideoWriter_fourcc(*'XVID')
videoWriter = cv2.VideoWriter('F:/3.avi',fourcc,fps,size)#最后一个是保存图片的尺寸
fourcc = cv2.VideoWriter_fourcc('M', 'P', '4', 'V' )
videoWriter = cv2.VideoWriter(video_out_path, fourcc, vedio_fps, video_size)#最后一个是保存图片的尺寸

#for(i=1;i<471;++i)
for i in range(1,327):
frame = cv2.imread(img_root+str(i)+'.jpg')
# frame = cv2.imread(img_input_path+str(i)+'.jpg')
frame = cv2.imread(img_input_path+ str(1) +'.jpg')
videoWriter.write(frame)
videoWriter.release()
videoWriter.release()

1 change: 1 addition & 0 deletions tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
video_out_path

0 comments on commit 882c922

Please sign in to comment.