{"id":309040,"date":"2020-08-26T15:00:39","date_gmt":"2020-08-26T15:00:39","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=309040"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=309040","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u0435\u043c thumbnails \u0434\u043b\u044f \u0432\u0438\u0434\u0435\u043e \u0441 python \u0438 opencv"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516662\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/zj\/pb\/mv\/zjpbmva2zje0vntwa_gzeyjsyr0.jpeg\"><\/p>\n<p>  \u041f\u043e\u0440\u043e\u0439, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0437\u0430\u0432\u0430\u043b\u044b \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438 \u043c\u0430\u043b\u044b\u0445 \u0432\u0438\u0434\u0435\u043e\u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043f\u0430\u043f\u043a\u0435(\u043f\u0430\u043f\u043a\u0430\u0445) \u043d\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430. \u0422\u0443\u0442 \u043d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 thumbnails, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043d\u0430\u0440\u0435\u0437\u043a\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u0432\u0438\u0434\u0435\u043e, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0441\u0442 thumbnails \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0430\u043f\u043a\u0435 windows, \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 timeline \u043a \u0432\u044b\u0440\u0435\u0437\u0430\u043d\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u0438\u043c\u043f\u043e\u0440\u0442 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0430 python:<\/p>\n<pre><code class=\"python\">import numpy as np import cv2 import os <\/code><\/pre>\n<p>  \u0423\u043a\u0430\u0436\u0435\u043c, \u0432 \u043a\u0430\u043a\u0430\u0439 \u043f\u0430\u043f\u043a\u0435 \u0438\u0441\u043a\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f:<\/p>\n<pre><code class=\"python\">file=file print('\u041f\u043e\u0434\u043e\u0436\u0434\u0438\u0442\u0435...') path=r'E:\\1' os.chdir(path) <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0432\u0441\u0435 \u0444\u0430\u0439\u043b\u044b \u043d\u0430 \u0434\u0438\u0441\u043a\u0435 E \u0432 \u043f\u0430\u043f\u043a\u0435 1.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0432\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432 \u0431\u043e\u0439 opencv, \u043d\u0430\u0440\u0435\u0437\u0430\u0435\u0442 \u043a\u0430\u0434\u0440\u044b \u0438 timeline \u043a \u043d\u0438\u043c:<\/p>\n<pre><code class=\"python\">vidcap = cv2.VideoCapture(path+'\\\\'+file)     fps = vidcap.get(cv2.CAP_PROP_FPS)     #print(fps)     n=12     total_frames = vidcap.get(cv2.CAP_PROP_FRAME_COUNT)     time_line = total_frames \/ fps      frames_step = total_frames\/\/n     time_line_step=time_line\/\/n     #print(int(time_line_step))     a=[]     b=[] <\/code><\/pre>\n<p>  n \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043d\u0430\u0440\u0435\u0437\u043a\u0435, 12 \u0448\u0442\u0443\u043a.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u0440\u0435\u0437\u043a\u0430 timeline \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445, \u0447\u0442\u043e\u0431\u044b \u043e\u043d\u0430 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0430\u0441\u044c \u043d\u0430 \u043a\u0430\u0434\u0440\u0430\u0445,<br \/>  \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0443\u044e \u043a \u0444\u043e\u0440\u043c\u0430\u0442\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 00:00:00:<\/p>\n<pre><code class=\"python\">def sec_to_time(t):         h=str(t\/\/3600)         m=(t\/\/60)%60         s=t%60         if m&lt;10:             m='0'+str(m)         else:             m=str(m)         if s&lt;10:             s='0'+str(s)         else:             s=str(s)             #print(h+':'+m+':'+s)         t=h+':'+m+':'+s         return t <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440 \u043d\u0430 50% \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0438\u0445 \u043d\u0430 \u0434\u0438\u0441\u043a, \u043a\u0430\u043a \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b:<\/p>\n<pre><code class=\"python\">for i in range(n):                 vidcap.set(1,i*frames_step)         success,image = vidcap.read()         #\u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u043c \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0443          scale_percent = 50         width = int(image.shape[1] * scale_percent \/ 100)         height = int(image.shape[0] * scale_percent \/ 100)         image=cv2.resize(image, (width, height))          # \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u0442\u0435\u043a\u0441\u0442\u0430 \u043a\u0440\u0430\u0441\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u0430 c time_line         font = cv2.FONT_HERSHEY_COMPLEX             t=int(time_line_step)*i             image=cv2.putText(image, sec_to_time(t), (100, 30), font, 0.5, color=(0, 0, 255), thickness=0)            cv2.imwrite('image'+str(i)+'.jpg',image)         a.append('image'+str(i)+'.jpg')     vidcap.release() <\/code><\/pre>\n<p>  \u0421\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f opencv, \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u0438, \u0441\u043e\u0431\u043b\u044e\u0434\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0441\u0442\u044c:<\/p>\n<pre><code class=\"python\">def glue (img1,img2,img3,x):         i1 = cv2.imread(img1)         i2 = cv2.imread(img2)         i3 = cv2.imread(img3)             vis = np.concatenate((i1, i2, i3), axis=1)         cv2.imwrite('out'+str(x)+'.png', vis)         b.append('out'+str(x)+'.png')     x=0     while x&lt;len(a):             glue(a[x],a[x+1],a[x+2],x)         x+=3 <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u00ab\u0442\u0440\u043e\u0439\u043a\u0438\u00bb \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u043f\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0438:<\/p>\n<pre><code class=\"python\"> #\u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0435\u043c \u0432\u0438\u0434\u0435\u043e \u043f\u043e \u0432\u0435\u0440\u0442\u0438\u043a\u0430\u043b\u0438     def glue2 (img1,img2,img3,img4):         i1 = cv2.imread(img1)         i2 = cv2.imread(img2)         i3 = cv2.imread(img3)         i4 = cv2.imread(img4)          vis = np.concatenate((i1, i2, i3,i4), axis=0)         cv2.imwrite(file[:-4]+'.jpeg', vis)     glue2(b[0],b[1],b[2],b[3]) <\/code><\/pre>\n<p>  \u041f\u0440\u0438\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432 \u043f\u0430\u043f\u043a\u0435, \u0443\u0434\u0430\u043b\u044f\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b:<\/p>\n<pre><code class=\"python\">#\u0443\u0431\u043e\u0440\u043a\u0430     c=['jpg', 'png']     for root, dirs, files in os.walk(path):             for file in files:             if file[-3:] in c:                 os.remove(file) <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0432\u043e\u0434\u0438\u043c \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0432\u0438\u0434\u0435\u043e\u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043f\u0430\u043f\u043a\u0435:<\/p>\n<pre><code class=\"python\">video=['wmv', 'mp4', 'avi', 'mov', 'MP4', '.rm', 'mkv'] for root, dirs, files in os.walk(r'E:\/1'):         for file in files:         if file[-3:] in video:             print('\u0412 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435-'+file)             tumbnail(file) <\/code><\/pre>\n<p>  \u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u043b\u044f \u0442\u0435\u0445, \u043a \u043a\u043e\u0438\u043c \u043e\u0442\u043d\u043e\u0448\u0443\u0441\u044c \u0438 \u044f, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u0434, \u0430 \u043f\u043e\u0442\u043e\u043c \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u044c\u044e \u2014 <a href=\"https:\/\/yadi.sk\/d\/ope4BvOQkcEfOw\" rel=\"nofollow\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c<\/a>.<\/p>\n<p>  P.S. timeline \u043d\u0435 \u0431\u0435\u0437 \u0433\u0440\u0435\u0445\u0430 \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 timeline \u0432\u0438\u0434\u0435\u043e.<\/p>\n<p>  \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u0437\u0430\u043c\u0435\u0442\u043d\u043e \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0432\u0438\u0434\u0435\u043e\u0444\u0430\u0439\u043b\u0430\u0445.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/516662\/\"> https:\/\/habr.com\/ru\/post\/516662\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/516662\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/zj\/pb\/mv\/zjpbmva2zje0vntwa_gzeyjsyr0.jpeg\"><\/p>\n<p>  \u041f\u043e\u0440\u043e\u0439, \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044f \u0437\u0430\u0432\u0430\u043b\u044b \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438 \u043c\u0430\u043b\u044b\u0445 \u0432\u0438\u0434\u0435\u043e\u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043f\u0430\u043f\u043a\u0435(\u043f\u0430\u043f\u043a\u0430\u0445) \u043d\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0437\u0430\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c \u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430. \u0422\u0443\u0442 \u043d\u0430 \u0443\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0442 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 thumbnails, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043d\u0430\u0440\u0435\u0437\u043a\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\u0437 \u0432\u0438\u0434\u0435\u043e, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u043c.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0441\u0442 thumbnails \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0430\u043f\u043a\u0435 windows, \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 timeline \u043a \u0432\u044b\u0440\u0435\u0437\u0430\u043d\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u0430\u043c.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-309040","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=309040"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/309040\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=309040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=309040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=309040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}