{"id":1767,"date":"2008-06-22T19:17:39","date_gmt":"2008-06-22T10:17:39","guid":{"rendered":"http:\/\/r-dimension.xsrv.jp\/classes_j\/?p=1767"},"modified":"2011-05-03T02:05:23","modified_gmt":"2011-05-02T17:05:23","slug":"frame_differencing","status":"publish","type":"post","link":"https:\/\/r-dimension.xsrv.jp\/classes_j\/frame_differencing\/","title":{"rendered":"\u30d5\u30ec\u30fc\u30e0\u5dee\u5206"},"content":{"rendered":"<p>\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u3001\u52d5\u4f5c\u91cf\u3092\u691c\u51fa\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p><!--more--><\/p>\n<pre lang=\"java\" line=\"1\">\r\n\/\/This code has been arranged by Yasushi Noguchi. Last updated on June 21, 2008.\r\n\/**\r\n * Frame Differencing \r\n * by Golan Levin. \r\n * \r\n * Quantify the amount of movement in the video frame using frame-differencing.\r\n *\/ \r\n\r\nimport processing.video.*;\r\n\r\nint numPixels;    \/\/\u753b\u50cf\u306e\u30d4\u30af\u30bb\u30eb\u306e\u7dcf\u6570\r\nint[] previousFrame;    \/\/\u4e00\u3064\u524d\u306e\u30d5\u30ec\u30fc\u30e0\r\nint noiseFilter = 100;    \/\/\u30ce\u30a4\u30ba\u3092\u62fe\u308f\u306a\u3044\u305f\u3081\u306e\u30d5\u30a3\u30eb\u30bf\uff08\u5024\u3092\u5897\u3084\u3059\u3068\u30d5\u30a3\u30eb\u30bf\u304c\u5f37\u304f\u304b\u304b\u308b\uff09\r\nCapture video;    \/\/\u30ad\u30e3\u30d7\u30c1\u30e3\u6620\u50cf\u7528\u306e\u5909\u6570\r\n\r\nvoid setup() {\r\n  size(640, 480);\r\n\r\n  video = new Capture(this, width, height, 24);\r\n  \/\/\u30ad\u30e3\u30d7\u30c1\u30e3\u30fc\u3059\u308b\u30d3\u30c7\u30aa\u753b\u50cf\u306e\u7dcf\u30d4\u30af\u30bb\u30eb\u6570\r\n  numPixels = video.width * video.height;\r\n  \/\/\u73fe\u5728\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u753b\u50cf\u3068\u6bd4\u3079\u308b\u305f\u3081\u306b\u4e00\u3064\u524d\u306e\u30d5\u30ec\u30fc\u30e0\u7528\u306e\u914d\u5217\u3092\u4f5c\u308b\r\n  previousFrame = new int[numPixels];\r\n  loadPixels();\r\n}\r\n\r\nvoid draw() {\r\n  if (video.available()) {  \/\/\u3082\u3057\u30ad\u30e3\u30d7\u30c1\u30e3\u304c\u3067\u304d\u305f\u3089\u3001\r\n    video.read(); \/\/\u30d3\u30c7\u30aa\u30d5\u30ec\u30fc\u30e0\u306e\u8aad\u307f\u8fbc\u307f\r\n    video.loadPixels(); \/\/\u30d3\u30c7\u30aa\u306e\u30d4\u30af\u30bb\u30eb\u3092\u64cd\u4f5c\u3067\u304d\u308b\u3088\u3046\u306b\u3059\u308b\r\n    \r\n    int movementSum = 0; \/\/\u4e00\u3064\u306e\u30d5\u30ec\u30fc\u30e0\u3067\u306e\u52d5\u4f5c\u91cf\r\n    for (int i = 0; i < numPixels; i++) { \/\/\u30d5\u30ec\u30fc\u30e0\u5185\u306e\u305d\u308c\u305e\u308c\u306e\u30d4\u30af\u30bb\u30eb\u3092\u691c\u51fa\r\n      color currColor = video.pixels[i];\r\n      color prevColor = previousFrame[i];\r\n      \r\n      \/\/\u73fe\u5728\u306e\u30d4\u30af\u30bb\u30eb\u306eR, G, B\u3092\u629c\u304d\u51fa\u3059\r\n      int currR = (currColor >> 16) & 0xFF;\r\n      int currG = (currColor >> 8 ) & 0xFF;\r\n      int currB = currColor & 0xFF;\r\n      \r\n      \/\/\u4e00\u3064\u524d\u306e\u30d5\u30ec\u30fc\u30e0\u306e\u8272\u3092\u629c\u304d\u51fa\u3059\r\n      int prevR = (prevColor >> 16) & 0xFF;\r\n      int prevG = (prevColor >> 8 ) & 0xFF;\r\n      int prevB = prevColor & 0xFF;\r\n      \r\n      \/\/\u73fe\u5728\u306e\u30d4\u30af\u30bb\u30eb\u304b\u3089\u524d\u306e\u30d4\u30af\u30bb\u30eb\u306e\u8272\u3092\u5f15\u3044\u305f\u7d76\u5bfe\u5024\r\n      int diffR = abs(currR - prevR);\r\n      int diffG = abs(currG - prevG);\r\n      int diffB = abs(currB - prevB);\r\n      \r\n      \/\/noiseFilter\u306e\u5024\u3088\u308a\u3082\u5927\u304d\u304b\u3063\u305f\u3089movementSum\u306b\u8db3\u3057\u3066\u3044\u304f\r\n      \/\/\u305d\u3057\u3066\u3001\u73fe\u5728\u306e\u8272\u306b\u66f4\u65b0\r\n      if(diffR + diffG + diffB > noiseFilter){\r\n        movementSum += diffR + diffG + diffB;\r\n        pixels[i] = color(currR, currG, currB);\r\n        \/\/\u6b21\u306e\u30b3\u30fc\u30c9\u306e\u65b9\u304c\u9ad8\u901f\u306b\u5b9f\u884c\u3067\u304d\u308b\u304c\u3001\u3061\u3087\u3063\u3068\u96e3\u3057\u3044\r\n        \/\/pixels[i] = 0xFF000000 | (currR < < 16) | (currG << 8 ) | currB;        \r\n      }\r\n      else{\r\n        \/\/\u305d\u3046\u3067\u306a\u3044\u5834\u5408\u306f\u9ed2\r\n        pixels[i] = color(0);\r\n      }\r\n\r\n      \/\/\u73fe\u5728\u306e\u30d5\u30ec\u30fc\u30e0\u306e\u8272\u3092\u524d\u306e\u30d5\u30ec\u30fc\u30e0\u306e\u8272\u306b\u3059\u308b\u3002\r\n      previousFrame[i] = currColor;\r\n    }\r\n    \r\n    updatePixels();    \/\/\u30d4\u30af\u30bb\u30eb\u3092\u66f4\u65b0\r\n    println(movementSum);    \/\/\u5909\u5316\u3057\u305f\u30d4\u30af\u30bb\u30eb\u306e\u7dcf\u6570\u3092\u30d7\u30ea\u30f3\u30c8\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u306e\u30b5\u30f3\u30d7\u30eb\u306f\u3001\u52d5\u4f5c\u91cf\u3092\u691c\u51fa\u3059\u308b\u305f\u3081\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,11],"tags":[],"class_list":["post-1767","post","type-post","status-publish","format-standard","hentry","category-processing","category-11"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/posts\/1767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/comments?post=1767"}],"version-history":[{"count":3,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/posts\/1767\/revisions"}],"predecessor-version":[{"id":2469,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/posts\/1767\/revisions\/2469"}],"wp:attachment":[{"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/media?parent=1767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/categories?post=1767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/tags?post=1767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}