Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775

Warning: Cannot modify header information - headers already sent by (output started at /home/cra-log/www/index.php:1) in /home/cra-log/www/site-admin-wp/wp-includes/rest-api/class-wp-rest-server.php on line 1775
{"id":244,"date":"2021-04-18T09:26:01","date_gmt":"2021-04-18T00:26:01","guid":{"rendered":"https:\/\/cra-log.sakura.ne.jp\/?p=244"},"modified":"2022-02-06T22:54:22","modified_gmt":"2022-02-06T13:54:22","slug":"python-opencv-camera-display","status":"publish","type":"post","link":"https:\/\/craft-gogo.com\/python-opencv-camera-display\/","title":{"rendered":"\u3010Python+OpenCV\u3011PC\u30ab\u30e1\u30e9\u3092\u4f7f\u3063\u3066\u52d5\u753b\u3092\u8868\u793a\u3057\u3088\u3046\uff01"},"content":{"rendered":"\n

OpenCV\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3001PC\u30ab\u30e1\u30e9\u304b\u3089\u52d5\u753b\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u305d\u306e\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0<\/h2>\n\n\n\n

\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u30a6\u30a3\u30f3\u30c9\u30a6\u304c\u7acb\u3061\u4e0a\u304c\u308a\u3001PC\u30ab\u30e1\u30e9\u3067\u6620\u3057\u51fa\u3055\u308c\u305f\u52d5\u753b\u3067\u8868\u793a\u3055\u308c\u307e\u3059\u3002\u300cq\u300d\u30ad\u30fc\u3092\u62bc\u3059\u3053\u3068\u3067\u30a6\u30a3\u30f3\u30c9\u30a6\u304c\u9589\u3058\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u7d42\u4e86\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

import cv2 as cv\n\nWIDTH: int = 320\nHEIGHT: int = 240\n\ncap = cv.VideoCapture(0)\nif not cap.isOpened():\n    print("Cannot open camera")\n    exit()\n\ncap.set(cv.CAP_PROP_FRAME_WIDTH, WIDTH)\ncap.set(cv.CAP_PROP_FRAME_HEIGHT, HEIGHT)\n\nprint("Width = ", cap.get(cv.CAP_PROP_FRAME_WIDTH))\nprint("Height = ", cap.get(cv.CAP_PROP_FRAME_HEIGHT))  \n\nwhile True:\n    # 1\u30d5\u30ec\u30fc\u30e0\u305a\u3064\u8aad\u307f\u8fbc\u3080\n    ret, frame = cap.read()\n\n    # \u30d5\u30ec\u30fc\u30e0\u304c\u6b63\u3057\u304f\u8aad\u307f\u8fbc\u307e\u308c\u306a\u3044\u5834\u5408\n    if not ret:\n        print("Can't receive frame")\n        break\n    \n    # \u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30ec\u30fc\u30e0\u3092\u8868\u793a\n    cv.imshow("frame", frame) \n    \n    #\u300cq\u300d\u30ad\u30fc\u304c\u62bc\u3055\u308c\u305f\u3089\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u9589\u3058\u308b\n    if cv.waitKey(1) & 0xFF == ord("q"):\n        break\n\ncap.release()\ncv.destroyAllWindows()<\/code><\/pre><\/div>\n\n\n\n

\u6b21\u9805\u3067\u306f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u8a73\u7d30\u3092\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n

VideoCapture\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u53d6\u5f97<\/h2>\n\n\n\n

\u307e\u305a\u3001VideoCapture()\u3067VideoCapture\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

cap = cv.VideoCapture(0)<\/code><\/pre><\/div>\n\n\n\n

\u5f15\u6570\u306f\u3001PC\u306b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u308b\u30ab\u30e1\u30e9\u756a\u53f7\u306b\u306a\u308a\u307e\u3059\u3002PC\u306b\u30ab\u30e1\u30e9\u304c1\u53f0\u3057\u304b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408\u306f\u300c0\u300d\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

if not cap.isOpened():\n    exit()<\/code><\/pre><\/div>\n\n\n\n

\u3082\u3057\u3001cap.isOpened()\u304cFalse\u3092\u8fd4\u3057\u305f\u306a\u3089\u3070\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d42\u4e86\u3059\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

\u89e3\u50cf\u5ea6\u306e\u5909\u66f4<\/h2>\n\n\n\n

openCV\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u306f\u3001\u89e3\u50cf\u5ea6\u306f640\u00d7480\u306e\u3088\u3046\u3067\u3059\u3002\u4eca\u56de\u306f320\u00d7240\u306e\u89e3\u50cf\u5ea6\u306b\u5909\u66f4\u3057\u307e\u3057\u305f\u3002\u30ab\u30e1\u30e9\u306e\u4ed5\u69d8\u306b\u3088\u308a\u89e3\u50cf\u5ea6\u306f\u81ea\u7531\u306b\u5909\u66f4\u3059\u308b\u3053\u3068\u306f\u51fa\u6765\u306a\u3044\u306e\u3067\u3001\u81ea\u8eab\u304c\u304a\u6301\u3061\u306e\u30ab\u30e1\u30e9\u4ed5\u69d8\u3092\u8abf\u3079\u3066\u4e0b\u3055\u3044\u3002<\/p>\n\n\n\n

\u89e3\u50cf\u5ea6\u306e\u5e45\u3068\u9ad8\u3055\u3092\u6307\u5b9a\u3057\u3066\u3001\u6307\u5b9a\u3057\u305f\u5024\u304c\u53cd\u6620\u3055\u308c\u3066\u3044\u308b\u304b\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

WIDTH: int = 320\nHEIGHT: int = 240\n\ncap.set(cv.CAP_PROP_FRAME_WIDTH, WIDTH)\ncap.set(cv.CAP_PROP_FRAME_HEIGHT, HEIGHT)\n\nprint("Width = ", cap.get(cv.CAP_PROP_FRAME_WIDTH))\nprint("Height = ", cap.get(cv.CAP_PROP_FRAME_HEIGHT))  <\/code><\/pre><\/div>\n\n\n\n

cap.set()\u306f\u52d5\u753b\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8a2d\u5b9a\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u7b2c1\u5f15\u6570\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3001\u7b2c2\u5f15\u6570\u306b\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

cap.get()\u306f\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u53d6\u5f97\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002\u7b2c1\u5f15\u6570\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

\u30d7\u30ed\u30d1\u30c6\u30a3<\/th>\u8aac\u660e<\/th><\/tr><\/thead>
CAP_PROP_FRAME_WIDTH<\/td>\u30d5\u30ec\u30fc\u30e0\u5e45<\/td><\/tr>
CAP_PROP_FRAME_HEIGHT<\/td>\u30d5\u30ec\u30fc\u30e0\u9ad8\u3055<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

cap.read()\u30671\u30d5\u30ec\u30fc\u30e0\u305a\u3064\u8aad\u307f\u8fbc\u3093\u3060\u753b\u50cf\u3092while\u6587\u3067\u7e70\u308a\u8fd4\u3057\u3001\u52d5\u753b\u306b\u3059\u308b<\/h2>\n\n\n\n

\u30ab\u30e1\u30e9\u304b\u3089\u9023\u7d9a\u3057\u305f\u753b\u50cf\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u3001cap.read()\u3067\u8aad\u307f\u8fbc\u3093\u3060\u753b\u50cf\u3092cv.imshow()\u3067\u8868\u793a\u3057\u3001while\u6587\u3067\u7e70\u308a\u8fd4\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

while True:\n    # 1\u30d5\u30ec\u30fc\u30e0\u305a\u3064\u8aad\u307f\u8fbc\u3080\n    ret, frame = cap.read()\n\n    # \u30d5\u30ec\u30fc\u30e0\u304c\u6b63\u3057\u304f\u8aad\u307f\u8fbc\u307e\u308c\u306a\u3044\u5834\u5408\n    if not ret:\n        print("Can't receive frame")\n        break\n    \n    # \u8aad\u307f\u8fbc\u3093\u3060\u30d5\u30ec\u30fc\u30e0\u3092\u8868\u793a\n    cv.imshow("frame", frame) \n    cv.waitKey(1)<\/code><\/pre><\/div>\n\n\n\n

cap.read()\u306f2\u3064\u306e\u623b\u308a\u5024\u3092\u8fd4\u3057\u307e\u3059\u30021\u3064\u76ee\u306f\u3001\u6b63\u3057\u304f\u30d5\u30ec\u30fc\u30e0\u304c\u8aad\u307f\u8fbc\u307e\u308c\u305f\u304b\u3069\u3046\u304bTrue\/False\u306eBoolean\u5024\u30022\u3064\u76ee\u306f\u8aad\u307f\u8fbc\u3093\u3060\u753b\u50cf\u30c7\u30fc\u30bf\u3067\u3059\u3002<\/p>\n\n\n\n

\u6b63\u3057\u304f\u30d5\u30ec\u30fc\u30e0\u304c\u8aad\u307f\u8fbc\u307e\u308c\u306a\u3044\u5834\u5408\u306f\u3001while\u6587\u3092\u629c\u3051\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u7d42\u4e86\u3055\u305b\u307e\u3059\u3002<\/p>\n\n\n\n

\u30d5\u30ec\u30fc\u30e0\u3092\u8aad\u307f\u8fbc\u3080\u3060\u3051\u3067\u306f\u3001\u30b9\u30af\u30ea\u30fc\u30f3\u306b\u8868\u793a\u3055\u308c\u306a\u3044\u306e\u3067\u3001cv.imshow()\u3067\u8868\u793a\u3055\u305b\u307e\u3059\u3002cv.imshow()\u306e\u7b2c1\u5f15\u6570\u306f\u3001\u8868\u793a\u3055\u305b\u308b\u30d5\u30ec\u30fc\u30e0\u306e\u540d\u79f0\u3092\u6587\u5b57\u5217\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002\u7b2c2\u5f15\u6570\u306f\u3001\u8aad\u307f\u8fbc\u3080\u753b\u50cf\u30c7\u30fc\u30bf\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

cv.imshow()\u3060\u3051\u3067\u306f\u3001\u51e6\u7406\u304c\u9ad8\u901f\u3059\u304e\u3066\u30a6\u30a3\u30f3\u30c9\u30a6\u306f\u771f\u3063\u9ed2\u306e\u307e\u307e\u8868\u793a\u3055\u308c\u3001\u56fa\u307e\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002cv.waitkey(1)\u30671ms\u51e6\u7406\u3092\u5f85\u6a5f\u3055\u305b\u308b\u3053\u3068\u3067\u52d5\u753b\u3068\u3057\u3066\u8868\u793a\u51fa\u6765\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

\u52d5\u753b\u8868\u793a\u306e\u7d42\u4e86<\/h2>\n\n\n\n

\u300cq\u300d\u30ad\u30fc\u304c\u62bc\u3055\u308c\u305f\u3089\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u9589\u3058\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n\n\n\n

while True:\n   #\u300cq\u300d\u30ad\u30fc\u304c\u62bc\u3055\u308c\u305f\u3089\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u9589\u3058\u308b\n   if cv.waitKey(1) & 0xFF == ord("q"):\n      break\n\ncap.release()\ncv.destroyAllWindows()<\/code><\/pre><\/div>\n\n\n\n

cv.waitKey()\u306f\u30ad\u30fc\u304c\u4f55\u3082\u62bc\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u304d-1\u3092\u8fd4\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001\u300cq\u300d\u304c\u62bc\u3055\u308c\u305f\u3089while\u6587\u3092\u629c\u3051\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n

cap.release()\u3067VideoCapture\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u89e3\u653e\u3057\u3001cv.destroyAllWindows()\u3067\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u9589\u3058\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u7d42\u4e86\u3067\u3059\u3002<\/p>\n\n\n\n

\u307e\u3068\u3081<\/h2>\n\n\n\n

\u4eca\u56de\u306f\u3001PC\u30ab\u30e1\u30e9\u3092\u4f7f\u3063\u3066\u52d5\u753b\u3092\u8868\u793a\u3059\u308b\u65b9\u6cd5\u3092\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n

\u8981\u70b9\u3092\u307e\u3068\u3081\u308b\u3068<\/p>\n\n\n\n

  • VideoCapture\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u53d6\u5f97\u3059\u308b<\/li>
  • \u89e3\u50cf\u5ea6\u3092\u5909\u66f4\u3059\u308b<\/li>
  • cap.read()\u30671\u30d5\u30ec\u30fc\u30e0\u305a\u3064\u8aad\u307f\u8fbc\u3093\u3060\u753b\u50cf\u3092while\u6587\u3067\u7e70\u308a\u8fd4\u3057\u3001\u52d5\u753b\u306b\u3059\u308b<\/li>
  • \u52d5\u753b\u8868\u793a\u306e\u7d42\u4e86<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"

    OpenCV\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3001PC\u30ab\u30e1\u30e9\u304b\u3089\u52d5\u753b\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u3002\u305d\u306e\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3059\u3002 \u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0 \u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u30a6\u30a3\u30f3\u30c9\u30a6\u304c\u7acb\u3061\u4e0a\u304c\u308a\u3001PC\u30ab\u30e1\u30e9\u3067\u6620\u3057\u51fa […]<\/p>\n","protected":false},"author":1,"featured_media":254,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[6,5],"tags":[],"_links":{"self":[{"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/posts\/244"}],"collection":[{"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/comments?post=244"}],"version-history":[{"count":20,"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":1093,"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/posts\/244\/revisions\/1093"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/media\/254"}],"wp:attachment":[{"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/media?parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/categories?post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craft-gogo.com\/wp-json\/wp\/v2\/tags?post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}