{"id":3567,"date":"2023-08-01T22:28:23","date_gmt":"2023-08-01T14:28:23","guid":{"rendered":"http:\/\/cnliutz.ipyingshe.net\/?p=3567"},"modified":"2023-11-30T20:00:11","modified_gmt":"2023-11-30T12:00:11","slug":"%e5%bd%95%e5%b1%8fpython%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=3567","title":{"rendered":"\u5f55\u5c4fpython\u4ee3\u7801"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#Here is a simple Python code for screen recording using OpenCV library:\n# ```python \n# ---- pip install numpy pillow opencv-python pyautogui ----\n# cv2 from package of  opencv-python\nimport cv2\nimport numpy as np\nimport pyautogui\n\n# Specify resolution\nresolution = (1920, 1080)\n#\u81ea\u52a8\u83b7\u53d6\u5c4f\u5e55\u5206\u8fa8\u7387\n#screen_width, screen_height = pyautogui.size()\r\n#fourcc = cv2.VideoWriter_fourcc(*\"XVID\")\r\n#out = cv2.VideoWriter(\"screen_recording.avi\", fourcc, 20.0, (screen_width, screen_height))\r\n\r\n# Specify video codec\ncodec = cv2.VideoWriter_fourcc(*\"XVID\")\n\n# Specify name of Output file\nfilename = \"Recording.avi\"\n\nfps = 60.0\nout = cv2.VideoWriter(filename, codec, fps, resolution)\nprint(\"\u5f00\u59cb\u5f55\u5236\u2026\u2026\u6587\u4ef6\u540d\uff1a\" + filename)\nprint(\"Ctrl+\u505c\u6b62\u5f55\u5236......\")\nwhile True:\n    img = pyautogui.screenshot()\n    frame = np.array(img)\n    frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)\n    out.write(frame)\n    if cv2.waitKey(1) == ord('q'):   #\u4e0d\u77e5\u4e3a\u4ec0\u4e48\uff0c\u6309q\u952e\u65e0\u6cd5\u9000\u51fa\u8fd0\u884c\uff01\uff01\uff01\n        print(\"ctrl+c\u7ed3\u675f\u5f55\u5c4f\")\n        break\n\nout.release()\ncv2.destroyAllWindows()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","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-3567","post","type-post","status-publish","format-standard","hentry","category-2","category-python"],"_links":{"self":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3567"}],"version-history":[{"count":4,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3567\/revisions"}],"predecessor-version":[{"id":3910,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/3567\/revisions\/3910"}],"wp:attachment":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3567"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}