{"id":2395,"date":"2022-06-09T10:50:45","date_gmt":"2022-06-09T02:50:45","guid":{"rendered":"http:\/\/cnliutz.uicp.io\/?p=2395"},"modified":"2022-06-09T10:50:45","modified_gmt":"2022-06-09T02:50:45","slug":"python%e5%bd%95%e5%b1%8f","status":"publish","type":"post","link":"http:\/\/0.ipyingshe.net:5347\/?p=2395","title":{"rendered":"python\u5f55\u5c4f"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>import time,threading\nfrom datetime import datetime\nfrom PIL import ImageGrab\n#from cv2 import *\nimport cv2\nimport numpy as np\nfrom pynput import keyboard\ndef video_record():   # \u5f55\u5165\u89c6\u9891\n  global name\n  fps=15\n  name = datetime.now().strftime('%Y-%m-%d %H-%M-%S') # \u5f53\u524d\u7684\u65f6\u95f4\uff08\u5f53\u6587\u4ef6\u540d\uff09\n  screen = ImageGrab.grab() # \u83b7\u53d6\u5f53\u524d\u5c4f\u5e55\n  width, high = screen.size # \u83b7\u53d6\u5f53\u524d\u5c4f\u5e55\u7684\u5927\u5c0f\n  fourcc = cv2.VideoWriter_fourcc('X', 'V', 'I', 'D') # MPEG-4\u7f16\u7801,\u6587\u4ef6\u540e\u7f00\u53ef\u4e3a.avi .asf .mov\u7b49\n  video = cv2.VideoWriter('%s.avi' % name, fourcc, fps, (width, high)) # \uff08\u6587\u4ef6\u540d\uff0c\u7f16\u7801\u5668\uff0c\u5e27\u7387\uff0c\u89c6\u9891\u5bbd\u9ad8\uff09\n  #print('3\u79d2\u540e\u5f00\u59cb\u5f55\u5236----')  # \u53ef\u9009\n  #time.sleep(3)\n  print('\u5f00\u59cb\u5f55\u5236!')\n  global start_time\n  start_time = time.time()\n  while True:\n    if flag:\n      print(\"\u5f55\u5236\u7ed3\u675f\uff01\")\n      global final_time\n      final_time = time.time()\n      video.release() #\u91ca\u653e\n      break\n    im = ImageGrab.grab()  # \u5c4f\u5e55\u6293\u56fe\uff0c\u56fe\u7247\u4e3aRGB\u6a21\u5f0f\n    frame = cv2.cvtColor(np.array(im), cv2.COLOR_RGB2BGR) # \u8f6c\u4e3aopencv\u7684BGR\u6a21\u5f0f\n    video.write(frame)  #\u5199\u5165vedio\u5b9a\u4e49\u7684\u6587\u4ef6\n    # time.sleep(5) # \u7b49\u5f855\u79d2\u518d\u6b21\u5faa\u73af,\u63a7\u5236\u5e27\u6570\n    #\u7b490.1\u6beb\u79d2---\u5341\u5206\u4e4b\u4e00\u79d2--10\u5e27\/\u79d2\ndef on_press(key):   # \u76d1\u542c\u6309\u952e-home\n  global flag\n  if key == keyboard.Key.home:\n    flag = True # \u6539\u53d8\n    return False # \u8fd4\u56deFalse\uff0c\u952e\u76d8\u76d1\u542c\u7ed3\u675f\uff01\ndef video_info():   # \u89c6\u9891\u4fe1\u606f\n  video = cv2.VideoCapture('%s.avi' % name)  # \u8bb0\u5f97\u6587\u4ef6\u540d\u52a0\u683c\u5f0f\u4e0d\u8981\u9519\uff01\n  fps = video.get(cv2.CAP_PROP_FPS)\n  Count = video.get(cv2.CAP_PROP_FRAME_COUNT)\n  size = (int(video.get(cv2.CAP_PROP_FRAME_WIDTH)), int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)))\n  print('\u5e27\u7387=%.1f'%fps)\n  print('\u5e27\u6570=%.1f'%Count)\n  print('\u5206\u8fa8\u7387',size)\n  print('\u89c6\u9891\u65f6\u95f4=%.3f\u79d2'%(int(Count)\/fps))\n  print('\u5f55\u5236\u65f6\u95f4=%.3f\u79d2'%(final_time-start_time))\n  print('\u63a8\u8350\u5e27\u7387=%.2f'%(fps*((int(Count)\/fps)\/(final_time-start_time))))\nif __name__ == '__main__':\n  flag = False\n  th = threading.Thread(target=video_record)\n  th.start()\n  with keyboard.Listener(on_press=on_press) as listener:\n    listener.join()\n  time.sleep(1)  # \u7b49\u5f85\u89c6\u9891\u91ca\u653e\u8fc7\u540e\n  video_info()\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>\u4ee3\u7801\u89e3\u91ca\uff1a<\/strong><\/p>\n\n\n\n<p>\u89c2\u5bdf\u4ee3\u7801\u53ef\u4ee5\u53d1\u73b0\u5b9e\u73b0\u5f55\u5c4f\u7684\u65b9\u5f0f\u5c31\u662f\u4e0d\u65ad\u5faa\u73af\u83b7\u53d6\u5c4f\u5e55\u7136\u540e\u5199\u5165\uff0c\u53ef\u4ee5\u60f3\u5230\u6bcf\u5faa\u73af\u4e00\u6b21\u5c31\u662f\u4e00\u5e27\uff0c\u800c\u5faa\u73af\u4e00\u6b21\u8981\u591a\u957f\u65f6\u95f4\u5c31\u53d6\u51b3\u4e8e\u8fd0\u884c\u7684\u901f\u5ea6\u4e86\u3002\u6240\u4ee5\u6211\u4eec\u53ea\u8981\u8ba9\u4e00\u79d2\u4e2d\u5199\u5165\u7684\u5e27\u6570\uff08\u4e5f\u5c31\u662f1\u79d2\u4e2d\u5faa\u73af\u7684\u6b21\u6570\uff09\u548cvideo\u4e2d\u7684\u53c2\u6570\u5e27\u7387\u76f8\u7b49\uff0c\u5c31\u80fd\u83b7\u5f97\u5dee\u4e0d\u591a\u6b63\u5e38\u7684\u901f\u5ea6<\/p>\n\n\n\n<p>\u56e0\u6b64\u6211\u5728\u4ee3\u7801\u4e2d\u52a0\u5165\u4e86\u89c6\u9891\u4fe1\u606f\uff0c\u7b97\u51fa\u4e86\u89c6\u9891\u64ad\u653e\u7684\u65f6\u95f4\u548c\u5f55\u5236\u65f6\u95f4\uff0c\u518d\u63a8\u7b97\u51fa\u6765\u6b63\u5e38\u901f\u5ea6\u7684\u5e27\u7387?\u63a8\u8350\u5e27\u7387\u3002\u53ea\u8981\u5148\u8fd0\u884c\u8bd5\u4e00\u4e0b\uff0c\u770b\u4e00\u4e0b\u63a8\u8350\u5e27\u7387\u662f\u591a\u5c11\uff0c\u518d\u628a\u4ee3\u7801\u4e2d\u7684\u53c2\u6570\u6539\u8fc7\u6765\u5c31\u884c\u4e86\uff08\u8981\u53d6\u6574\u6570\u54e6\uff09<\/p>\n\n\n\n<p>\u5f00\u59cb\u5f55\u5236! \u5f55\u5236\u7ed3\u675f\uff01 \u5e27\u7387=15.0 \u5e27\u6570=446.0 \u5206\u8fa8\u7387 (1600, 900) \u89c6\u9891\u65f6\u95f4=29.733\u79d2 \u5f55\u5236\u65f6\u95f4=22.233\u79d2 \u63a8\u8350\u5e27\u7387=20.06<\/p>\n\n\n\n<p><strong>\u8981\u6309home\u952e\u6765\u6b63\u5e38\u7ed3\u675f\u7a0b\u5e8f\uff0c\u624d\u4f1a\u6709video_info\u51fa\u73b0<\/strong><\/p>\n\n\n\n<p>\u6211\u5728\u5faa\u73af\u4e2d\u52a0\u5165\u4e86\u2018\u7b49\u5f855\u79d2\u2019\uff0c\u8fd9\u6837\u5c31\u5dee\u4e0d\u591a\u6bcf5\u79d2\u83b7\u53d61\u5e27\uff0c\u63a8\u8350\u5e27\u7387\u663e\u793a0.20\uff0c\u5f53\u7136\uff0c\u6211\u4e0d\u80fd\u4e5f\u4e0d\u4f1a\u6309\u8fd9\u4e2a\u901f\u5ea6\u64ad\u653e\uff0c\u7ed9\u5b83\u6765\u4e2a25\u500d\uff08\u5e27\u7387\u4e3a0.20*25=5\uff0c\u8fd9\u6837\u89c6\u9891\u51fa\u6765\u5c31\u53c8\u5c0f\u53c8\u77ed\u4e86?\uff09<\/p>\n\n\n\n<p>\u591a\u63d0\u4e00\u4e0b\uff0c\u56e0\u4e3a\u4e24\u4e2a\u7ebf\u7a0b\u5e76\u4e0d\u4f1a\u540c\u65f6\u7ed3\u675f\uff0c\u53ea\u662f\u901a\u8fc7flag\u8fd9\u4e2a\u53d8\u91cf\u6539\u53d8\u6765\u4f7f\u5f97\u53e6\u4e00\u4e2a\u7ed3\u675f\uff0c\u6240\u4ee5\u6309home\u952eflag\u6539\u53d8\u7684\u65f6\u5019\uff0c\u53e6\u4e00\u4e2a\u7ebf\u7a0bvideo_record\u8fd8\u5904\u4e8e\u8fd0\u884c\u5faa\u73af\u4e2d\uff0c\u56e0\u6b64\u6211\u4eec\u8981\u7b49\u5b83\u7ecf\u8fc7\u8fd9\u6b21\u5faa\u73af\uff0c\u8fdb\u5165\u4e0b\u4e00\u6b21\u6761\u4ef6\u5224\u65ad\uff0c\u89c6\u9891\u624d\u5f97\u4ee5\u4ece\u5185\u5b58\u91ca\u653e\u2026\u5443\u55ef\uff0c\u5c31\u662f\u6211\u8981\u5728\u4ee3\u7801\u5012\u6570\u7b2c2\u884c\u90a3\u91cc\u7b49\u5f85\u4e2a5+1=6\u79d2\uff08\u8fd9\u6837\u6bd4\u8f83\u4fdd\u9669\uff09\uff0c\u5426\u5219\u7684\u8bdd\uff0c\u90a3\u4e2a\u5e27\u6570\u4f1a\u663e\u793a\u4e3a0\uff0c\u751a\u81f3\u4f1a\u51fa\u73b0\u8fd0\u884c\u9519\u8bef\uff08\u4e0d\u80fd\u96640\uff09<\/p>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p>\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8epython\u5b9e\u73b0\u5f55\u5c4f\u529f\u80fd\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86,\u66f4\u591a\u76f8\u5173python \u5b9e\u73b0\u5f55\u5c4f\u5185\u5bb9\u8bf7\u641c\u7d22ZaLou.Cn<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee3\u7801\u89e3\u91ca\uff1a \u89c2\u5bdf\u4ee3\u7801\u53ef\u4ee5\u53d1\u73b0\u5b9e\u73b0\u5f55\u5c4f\u7684\u65b9\u5f0f\u5c31\u662f\u4e0d\u65ad\u5faa\u73af\u83b7\u53d6\u5c4f\u5e55\u7136\u540e\u5199\u5165\uff0c\u53ef\u4ee5\u60f3\u5230 <span class=\"readmore\"><a href=\"http:\/\/0.ipyingshe.net:5347\/?p=2395\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,10],"tags":[],"class_list":["post-2395","post","type-post","status-publish","format-standard","hentry","category-2","category-python"],"_links":{"self":[{"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2395","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2395"}],"version-history":[{"count":0,"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2395\/revisions"}],"wp:attachment":[{"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2395"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2395"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/0.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2395"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}