Recent fire in Wuhan cherry blossoms open program code

cv_2.py

import CV2


vidcap = cv2.VideoCapture('video/video.avi')

count = 0

while True:

    success, image = vidcap.read()

    if success:

        cv2.imwrite("pic/frame%d.jpg" % count,image) # save frame as JPEG file

        if cv2.waitKey(10) == 27:

            break

        count += 1


print ( 'video to picture processing is completed!')

1

2

3

4

5

6

7

8

9

10

11

12

13

cv_3.py

from PIL import Image,ImageDraw,ImageFont

import CV2

import os



def draw(pic):

    img = cv2.imread('pic/' + pic)

    img = img[:,:,(2,1,0)]


    blank = Image.new("RGB", [len(img[0]),len(img)], "white")

    drawObj = ImageDraw.Draw(blank)


    n = 10


    font = ImageFont.truetype('C:/Windows/Fonts/Microsoft YaHei UI/msyhbd.ttc',size=n-1)

    for i in range(0, len(img),n):

        for j in range(0, len(img[i]), n):

            text = 'Wuhan refueling'

            drawObj.ink = img[i][j][0] + img[i][j][1]*256 + img[i][j][2]*256*256

            drawObj.text([j,i], text[int(j/n)%len(text)],font=font)

            print ( 'processing is completed ----', i, j)


    blank.save('new/new_'+pic, 'jpeg')


filelist = os.listdir('pic')

for file in filelist:

    draw(file)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

cv_4.py

import os

import CV2

import re


def resort(list):

    for i in range(len(list)-1):

        for j in range(len(list) - 1):

            if int(re.findall(r'\d+', list[j])[0]) > int(re.findall(r'\d+', list[j+1])[0]):

                list[j], list[j+1] = list[j+1], list[j]

    return list



def PicVideo (path, size):

    '''


    : Param path: the folder where the pictures

    : Param size: Image Resolution

    :return:

    '''

    filelist = os.listdir(path)

    filelist = resort(filelist)



    '''

    fps:

    Frame rate: 1 second n pictures have written into [such as controlling a picture for 5 seconds, then the frame rate is 1 need to repeat this image 5]

    There are 50 pictures in under 534 * 300 If the folder, where 1 is set to play five seconds, then the duration of this video is 10 seconds

    '''

    fps = 24

    file_path = 'video/new.mp4'

    Different fourcc = cv2.VideoWriter_fourcc ( 'D', 'I', 'V', 'X') # corresponding to different video coding format video

    video = cv2.VideoWriter(file_path, fourcc, fps, size)


    for item in filelist:

        if item.endswith('.jpg'):

            item = path + '/' + item

            img = cv2.imread (item) ## to read images using opencv directly back numpy.ndarray objects, the BGR channel order, the BGR is noted, the default value channel 0-255

            video.write (img) # written into the video picture

    video.release () # release

Zhengzhou infertility hospital: http: //www.zzchyy110.com/

PicVideo (r'new ', (960,544))

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

note:


(1) do not directly pip install cv2, but pip install opencv-python install module cv2

(2) self-cherry blossom go online to download the original video, larger than 900 M

(3) With this demo since you can play things that gadgets


Guess you like

Origin blog.51cto.com/14510351/2484383