{"id":639,"date":"2023-08-20T19:48:13","date_gmt":"2023-08-20T11:48:13","guid":{"rendered":"https:\/\/wangliguang.cn\/?p=639"},"modified":"2023-08-20T21:39:45","modified_gmt":"2023-08-20T13:39:45","slug":"%e3%80%902023%e6%96%b0%e6%95%99%e7%a8%8b%e3%80%91%e6%a0%91%e8%8e%93%e6%b4%be%e5%ae%9a%e6%97%b6%e8%87%aa%e5%8a%a8%e6%8b%8d%e7%85%a7%e5%b9%b6%e4%b8%8a%e4%bc%a0%e8%85%be%e8%ae%af%e4%ba%91%e5%af%b9","status":"publish","type":"post","link":"https:\/\/wangliguang.cn\/?p=639","title":{"rendered":"\u30102023\u65b0\u6559\u7a0b\u3011\u6811\u8393\u6d3e\u5b9a\u65f6\u81ea\u52a8\u62cd\u7167\u5e76\u4e0a\u4f20\u817e\u8baf\u4e91\u5bf9\u8c61\u5b58\u50a8COS"},"content":{"rendered":"<h2>1 \u6362\u6e90<\/h2>\n<p><strong>\u4ec5\u9002\u7528\u4e8e<code>Release date: May 3rd 2023\u3001Debian version: 11 (bullseye)<\/code>\u8fd9\u4e2a\u6811\u8393\u6d3eOS\u7248\u672c\uff0c\u5176\u4ed6\u7248\u672c\u4e0d\u4fdd\u8bc1\u6709\u6548\u3002<\/strong><\/p>\n<p>\u9996\u5148\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff0c\u67e5\u770b\u81ea\u5df1\u6811\u8393\u6d3e\u7684\u67b6\u6784\u3002<\/p>\n<pre><code>uname -a<\/code><\/pre>\n<p>\u7ed3\u679c\u5982\u4e0b\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/liguang.wang\/usr\/uploads\/2023\/08\/510194814.png\" alt=\"\u5c4f\u5e55\u622a\u56fe 2023-08-20 193101.png\" \/><\/p>\n<p>\u5982\u679c\u7ea2\u5708\u5904\u663e\u793a\u4e3a<code>aarch64<\/code>\uff0c\u4f7f\u7528\u547d\u4ee4<code>sudo nano \/etc\/apt\/sources.list<\/code>\uff0c\u6ce8\u91ca\u6389\u91cc\u9762\u7684\u6240\u6709\u5185\u5bb9\uff0c\u52a0\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre><code># \u9ed8\u8ba4\u6ce8\u91ca\u4e86\u6e90\u7801\u955c\u50cf\u4ee5\u63d0\u9ad8 apt update \u901f\u5ea6\uff0c\u5982\u6709\u9700\u8981\u53ef\u81ea\u884c\u53d6\u6d88\u6ce8\u91ca\ndeb https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bullseye main contrib non-free\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bullseye main contrib non-free\n\ndeb https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bullseye-updates main contrib non-free\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bullseye-updates main contrib non-free\n\ndeb https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bullseye-backports main contrib non-free\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian\/ bullseye-backports main contrib non-free\n\n# deb https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian-security bullseye-security main contrib non-free\n# # deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/debian-security bullseye-security main contrib non-free\n\ndeb https:\/\/security.debian.org\/debian-security bullseye-security main contrib non-free\n# deb-src https:\/\/security.debian.org\/debian-security bullseye-security main contrib non-free<\/code><\/pre>\n<p>\u7136\u540e\u4fdd\u5b58\u3002<br \/>\n\u5982\u679c\u7ea2\u5708\u5904\u663e\u793a<code>armv7l<\/code>\uff0c\u5219\u4f7f\u7528\u547d\u4ee4<code>sudo nano \/etc\/apt\/sources.list<\/code>\uff0c\u6ce8\u91ca\u6389\u91cc\u9762\u7684\u6240\u6709\u5185\u5bb9\uff0c\u52a0\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre><code>deb https:\/\/mirrors.tuna.tsinghua.edu.cn\/raspbian\/raspbian\/ bullseye main non-free contrib rpi\n# deb-src https:\/\/mirrors.tuna.tsinghua.edu.cn\/raspbian\/raspbian\/ bullseye main non-free contrib rpi\n\n# deb [arch=arm64] https:\/\/mirrors.tuna.tsinghua.edu.cn\/raspbian\/multiarch\/ bullseye main<\/code><\/pre>\n<p><strong>\u6ce8\u610f\u4e24\u8005\u4e0d\u53ef\u540c\u65f6\u9009\u62e9\u3002<\/strong><br \/>\n\u505a\u5b8c\u4e0a\u8ff0\u6b65\u9aa4\u540e\uff0c\u4f7f\u7528\u547d\u4ee4<code>sudo nano \/etc\/apt\/sources.list.d\/raspi.list <\/code>\uff0c\u6ce8\u91ca\u6389\u91cc\u9762\u7684\u6240\u6709\u5185\u5bb9\uff0c\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre><code>deb https:\/\/mirrors.tuna.tsinghua.edu.cn\/raspberrypi\/ bullseye main<\/code><\/pre>\n<p>\u7136\u540e\u4fdd\u5b58\u3002<br \/>\n\u6267\u884c<code>sudo apt-get update<\/code>.<\/p>\n<h2>2 \u5b89\u88c5OpenCV<\/h2>\n<p>\u4f7f\u7528\u547d\u4ee4<code>sudo apt-get install python3-opencv -y<\/code>\u5b89\u88c5OpenCV\u3002<\/p>\n<h2>3 \u7f16\u5199\u4ee3\u7801<\/h2>\n<p>\u5728\/home\/pi\u4e0b\u521b\u5efaproject\u6587\u4ef6\u5939\uff0c\u5728\u8be5\u6587\u4ef6\u5939\u4e2d\u518d\u521b\u5efa\u6587\u4ef6\u5939\u4e2d\u521b\u5efaimg\u6587\u4ef6\u5939\u3001code.py\u6587\u4ef6\u3002<br \/>\n\u5728code.py\u6587\u4ef6\u4e2d\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre><code># -*- coding=utf-8\nimport time\nimport datetime  #\u65e5\u671f\u65f6\u95f4\nimport os  #\u6587\u4ef6\u64cd\u4f5c\nimport cv2  #opencv-python\nfrom qcloud_cos import CosConfig\nfrom qcloud_cos import CosS3Client\nimport sys\nimport os\nimport logging\n\n# \u6b63\u5e38\u60c5\u51b5\u65e5\u5fd7\u7ea7\u522b\u4f7f\u7528 INFO\uff0c\u9700\u8981\u5b9a\u4f4d\u65f6\u53ef\u4ee5\u4fee\u6539\u4e3a DEBUG\uff0c\u6b64\u65f6 SDK \u4f1a\u6253\u5370\u548c\u670d\u52a1\u7aef\u7684\u901a\u4fe1\u4fe1\u606f\nlogging.basicConfig(level=logging.INFO, stream=sys.stdout)\n\n# 1. \u8bbe\u7f6e\u7528\u6237\u5c5e\u6027, \u5305\u62ec secret_id, secret_key, region\u7b49\u3002Appid \u5df2\u5728 CosConfig \u4e2d\u79fb\u9664\uff0c\u8bf7\u5728\u53c2\u6570 Bucket \u4e2d\u5e26Appid\u3002Bucket \u7531 BucketName-Appid \u7ec4\u6210\nsecret_id = &#039;\u4f60\u7684ID&#039;     # \u7528\u6237\u7684 SecretId\uff0c\u5efa\u8bae\u4f7f\u7528\u5b50\u8d26\u53f7\u5bc6\u94a5\uff0c\u6388\u6743\u9075\u5faa\u6700\u5c0f\u6743\u9650\u6307\u5f15\uff0c\u964d\u4f4e\u4f7f\u7528\u98ce\u9669\u3002\u5b50\u8d26\u53f7\u5bc6\u94a5\u83b7\u53d6\u53ef\u53c2\u89c1 https:\/\/cloud.tencent.com\/document\/product\/598\/37140\nsecret_key = &#039;\u4f60\u7684key&#039;   # \u7528\u6237\u7684 SecretKey\uff0c\u5efa\u8bae\u4f7f\u7528\u5b50\u8d26\u53f7\u5bc6\u94a5\uff0c\u6388\u6743\u9075\u5faa\u6700\u5c0f\u6743\u9650\u6307\u5f15\uff0c\u964d\u4f4e\u4f7f\u7528\u98ce\u9669\u3002\u5b50\u8d26\u53f7\u5bc6\u94a5\u83b7\u53d6\u53ef\u53c2\u89c1 https:\/\/cloud.tencent.com\/document\/product\/598\/37140\nregion = &#039;ap-guangzhou&#039;      # \u66ff\u6362\u4e3a\u7528\u6237\u7684 region\uff0c\u5df2\u521b\u5efa\u6876\u5f52\u5c5e\u7684 region \u53ef\u4ee5\u5728\u63a7\u5236\u53f0\u67e5\uff0chttps:\/\/console.cloud.tencent.com\/cos5\/bucket\n                           # COS \u652f\u6301\u7684\u6240\u6709 region \u5217\u8868\u53c2\u89c1 https:\/\/cloud.tencent.com\/document\/product\/436\/6224\ntoken = None               # \u5982\u679c\u4f7f\u7528\u6c38\u4e45\u5bc6\u94a5\u4e0d\u9700\u8981\u586b\u5165 token\uff0c\u5982\u679c\u4f7f\u7528\u4e34\u65f6\u5bc6\u94a5\u9700\u8981\u586b\u5165\uff0c\u4e34\u65f6\u5bc6\u94a5\u751f\u6210\u548c\u4f7f\u7528\u6307\u5f15\u53c2\u89c1 https:\/\/cloud.tencent.com\/document\/product\/436\/14048\nscheme = &#039;https&#039;           # \u6307\u5b9a\u4f7f\u7528 http\/https \u534f\u8bae\u6765\u8bbf\u95ee COS\uff0c\u9ed8\u8ba4\u4e3a https\uff0c\u53ef\u4e0d\u586b\n\nconfig = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Scheme=scheme)\nclient = CosS3Client(config)\n\ncamera = cv2.VideoCapture(0)  #\u4e00\u4e2a\u6444\u50cf\u5934\uff0c\u540e\u671f\u53ef\u6269\u5c55\u591a\u4e2a\u6444\u50cf\u5934\n\ndef delete_imgs():\n    delete_url = &quot;\/home\/pi\/project\/img&quot;\n    delete_list = os.listdir(delete_url)\n    #print(delete_list)\n    for i in range(len(delete_list)):\n        os.remove(delete_url+&#039;\/&#039;+delete_list[i])\n    logging.info(&quot;delete all imgs success!&quot;)\n\nif camera.isOpened():\n    logging.info(&quot;Start Picture!&quot;)\n    while True:\n        # \u8bbe\u7f6e\u5206\u8fa8\u7387\n        camera.set(3, 1920)  #width\n        camera.set(4, 1080)  #height\n        ret, img = camera.read()\n        date = datetime.datetime.now().strftime(&quot;%Y-%m-%d&quot;)\n        get_photo_time = datetime.datetime.now().strftime(&quot;%Y-%m-%d_%H-%M-%S&quot;)\n        #print(get_photo_time)\n        file_path = &quot;\/home\/pi\/regular-photos-of-raspberry-pie\/img\/&quot; + str(get_photo_time) + &quot;.jpg&quot;\n        cv2.imwrite(file_path,img)  #\u4fdd\u5b58\u5230\u6811\u8393\u6d3e\u672c\u5730\n        upload_time = datetime.datetime.now().strftime(&quot;%Y-%m-%d_%H-%M-%S&quot;)\n        #print(upload_time)\n        response = client.upload_file(\n            Bucket=&#039;raspberry1-1257204660&#039;,\n            LocalFilePath=file_path,\n            Key=&quot;getRasberryImgs\/&quot;+ date + &quot;\/&quot; + str(upload_time)+ &quot;.jpg&quot;,\n            PartSize=1,\n            MAXThread=10,\n            EnableMD5=False\n        )\n        os.remove(file_path)  #\u5220\u9664\u6811\u8393\u6d3e\u672c\u5730\u5df2\u4fdd\u5b58\u6587\u4ef6\/\/\u6709\u65f6\u5019\u56e0\u4e3a\u8fdb\u7a0b\u5148\u540e\uff0c\u6709\u4e9b\u56fe\u7247\u6587\u4ef6\u6765\u4e0d\u53ca\u5220\u9664\n\n        #\u5224\u65adimg\u6587\u4ef6\u4e2d\u6709\u6ca1\u6709\u7167\u7247\uff0c\u5220\u9664\u6389\n        nums = os.listdir(&#039;\/home\/pi\/regular-photos-of-raspberry-pie\/img&#039;)#\u5220\u9664\u6765\u4e0d\u53ca\u5220\u9664\u7684\u7167\u7247\n        if nums:\n            delete_imgs()\n        # camera.release()\n        time.sleep(3600)<\/code><\/pre>\n<p>\u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u5373\u53ef\u5b8c\u6210\u6bcf\u5c0f\u65f6\u62cd\u4e00\u5f20\u7167\u5e76\u4e0a\u4f20\u5230\u817e\u8baf\u4e91\u5bf9\u8c61\u5b58\u50a8COS\u4e2d\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<p><a href=\"https:\/\/blog.csdn.net\/weixin_46709801\/article\/details\/128045344\">https:\/\/blog.csdn.net\/weixin_46709801\/article\/details\/128045344<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1 \u6362\u6e90 \u4ec5\u9002\u7528\u4e8eRelease date: May 3rd 2023\u3001Debian version: 11 &hellip; <a href=\"https:\/\/wangliguang.cn\/?p=639\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u30102023\u65b0\u6559\u7a0b\u3011\u6811\u8393\u6d3e\u5b9a\u65f6\u81ea\u52a8\u62cd\u7167\u5e76\u4e0a\u4f20\u817e\u8baf\u4e91\u5bf9\u8c61\u5b58\u50a8COS<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,9,18],"tags":[],"class_list":["post-639","post","type-post","status-publish","format-standard","hentry","category-diy","category-python","category-18"],"_links":{"self":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/639","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=639"}],"version-history":[{"count":2,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/639\/revisions"}],"predecessor-version":[{"id":641,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=\/wp\/v2\/posts\/639\/revisions\/641"}],"wp:attachment":[{"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wangliguang.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}