{"id":715,"date":"2022-12-15T16:57:55","date_gmt":"2022-12-15T08:57:55","guid":{"rendered":"http:\/\/wordpress.loc\/?p=715"},"modified":"2022-12-17T16:44:38","modified_gmt":"2022-12-17T08:44:38","slug":"esp32_ch2-12","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/12\/15\/715\/","title":{"rendered":"Python\u958b\u555fESP32CAM\u57f7\u884c\u932f\u8aa4\u554f\u984c"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>\u6700\u8fd1\u5e38\u7528Python\u53bb\u63a5ESP32CAM\u5f71\u50cf\u56de\u4f86\u8fa8\u8b58\uff0c\u4f8b\u5982\u7b97\u4e00\u4e0b\u5e7e\u500b\u4eba\u3001\u5e7e\u53f0\u8eca\u7d93\u904e\u9019\u985e\u7684\u554f\u984c\uff0c\u4e0d\u904eESP32CAM\u50b3\u8f38\u900f\u904e\u7db2\u8def\uff0c\u7e3d\u662f\u5076\u723e\u6703\u65b7\u7dda<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<p>\u6700\u8fd1\u5e38\u7528Python\u53bb\u63a5ESP32CAM\u5f71\u50cf\u56de\u4f86\u8fa8\u8b58\uff0c\u4f8b\u5982\u7b97\u4e00\u4e0b\u5e7e\u500b\u4eba\u3001\u5e7e\u53f0\u8eca\u7d93\u904e\u9019\u985e\u7684\u554f\u984c\uff0c\u4e0d\u904eESP32CAM\u50b3\u8f38\u900f\u904e\u7db2\u8def\uff0c\u7e3d\u662f\u5076\u723e\u6703\u65b7\u7dda\uff0c\u4e4b\u524d\u5beb\u7684\u7a0b\u5f0f\u53ea\u8981\u4e00\u6bb5\u6642\u9593\u5c31\u6703\u51fa\u932f\uff0c\u5c0e\u81f4\u4e09\u4e0d\u4e94\u6642\u5c31\u8981\u53bb\u81ea\u5df1\u91cd\u65b0\u6309\u555f\u52d5\u3002<\/p>\n\n\n\n<p>python\u6211\u7b97\u662f\u65b0\u624b\uff0c\u6709\u4e9b\u57fa\u790e\u8a9e\u6cd5\u5230\u662f\u6c92\u90a3\u9ebc\u719f\uff0c\u5176\u5be6\u53ea\u8981\u52a0\u5165\u6211\u5728.net\u7a0b\u5f0f\u4e2d\u4e00\u5b9a\u6703\u7528\u5230\u7684try catch\u5c31\u53ef\u4ee5\u89e3\u6c7a\u4e86\u3002<\/p>\n\n\n\n<p>1.ESP32CAM\u8acb\u5b89\u88dd\u7bc4\u4f8b\u7a0b\u5f0f\uff1aCamerawebserver\uff0c\u9019\u90e8\u4efd\u8acb\u53c3\u8003\uff1a<a href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/03\/esp32_ch2\/\">ESP32-CAM (arduino)\u5f71\u50cf\u4f3a\u670d\u5668\u53ca\u81c9\u90e8\u8fa8\u8b58\u6559\u5b78\u539f\u59cb\u6a94Video Stream Server<\/a><\/p>\n\n\n\n<p>2.\u57f7\u884c\u5f8c\uff0c\u5728\u5e8f\u5217\u8996\u7a97\u67e5\u770b\u53d6\u5f97\u7684IP<\/p>\n\n\n\n<p>3.\u57f7\u884c\u672cpython\u7a0b\u5f0f<\/p>\n\n\n\n<p>\u5b8c\u6574\u7a0b\u5f0f\u78bc\u53ef\u4ee5\u5728\u9019\u88e1\u4e0b\u8f09\uff1a<a href=\"https:\/\/github.com\/youjunjer\/Python-Read-ESP32CAM\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/youjunjer\/Python-Read-ESP32CAM<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#ESP32CAM\u8acb\u4f7f\u7528CamerawebServer\u7bc4\u4f8b\u7a0b\u5f0f\nimport cv2 as cv\nimport numpy as np\nfrom urllib.request import urlopen\n\n#change to your ESP32-CAM ip\nurl=\"http:\/\/192.168.1.102:81\/stream\"\nCAMERA_BUFFRER_SIZE=2048\nstream=urlopen(url)\nbts=b''\ni=0\nwhile True:    \n    try:\n        bts+=stream.read(CAMERA_BUFFRER_SIZE)\n        jpghead=bts.find(b'\\xff\\xd8')\n        jpgend=bts.find(b'\\xff\\xd9')\n        if jpghead>-1 and jpgend>-1:\n            jpg=bts&#91;jpghead:jpgend+2]\n            bts=bts&#91;jpgend+2:]\n            img=cv.imdecode(np.frombuffer(jpg,dtype=np.uint8),cv.IMREAD_UNCHANGED)\n            #img=cv.flip(img,0) #>0:\u5782\u76f4\u7ffb\u8f49, 0:\u6c34\u5e73\u7ffb\u8f49, &lt;0:\u5782\u76f4\u6c34\u5e73\u7ffb\u8f49            \n            #h,w=img.shape&#91;:2]\n            #print('\u5f71\u50cf\u5927\u5c0f \u9ad8:' + str(h) + '\u5bec\uff1a' + str(w))\n            img=cv.resize(img,(800,600))\n            cv.imshow(\"a\",img)\n        k=cv.waitKey(1)\n    except Exception as e:\n        print(\"Error:\" + str(e))\n        bts=b''\n        stream=urlopen(url)\n        continue\n    \n    k=cv.waitKey(1)\n    # \u6309a\u62cd\u7167\u5b58\u6a94\n    if k &amp; 0xFF == ord('a'):\n        cv.imwrite(str(i) + \".jpg\", img)\n        i=i+1\n    # \u6309q\u96e2\u958b\n    if k &amp; 0xFF == ord('q'):\n        break\ncv.destroyAllWindows()\n\n\n <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5e38\u7528Python\u53bb\u63a5ESP32CAM\u5f71\u50cf\u56de\u4f86\u8fa8\u8b58\uff0c\u4f8b\u5982\u7b97\u4e00\u4e0b\u5e7e\u500b\u4eba\u3001\u5e7e\u53f0\u8eca\u7d93\u904e\u9019\u985e\u7684\u554f\u984c\uff0c\u4e0d\u904eESP32C [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1,26,5],"tags":[],"class_list":["post-715","post","type-post","status-publish","format-standard","hentry","category-esp32","category-esp32cam","category-python"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=715"}],"version-history":[{"count":1,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/715\/revisions"}],"predecessor-version":[{"id":716,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/715\/revisions\/716"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}