{"id":1853,"date":"2010-06-09T19:41:36","date_gmt":"2010-06-09T10:41:36","guid":{"rendered":"http:\/\/r-dimension.xsrv.jp\/classes_j\/?p=1853"},"modified":"2011-05-03T01:21:59","modified_gmt":"2011-05-02T16:21:59","slug":"difference_circle","status":"publish","type":"post","link":"https:\/\/r-dimension.xsrv.jp\/classes_j\/difference_circle\/","title":{"rendered":"\u753b\u50cf\u51e6\u7406\u306e\u30b5\u30f3\u30d7\u30eb\uff08difference_circle\uff09"},"content":{"rendered":"<p>\u4eba\u304c\u52d5\u3044\u305f\u5f8c\u306b\u3044\u308d\u3044\u308d\u306a\u30a8\u30d5\u30a7\u30af\u30c8\u304c\u304b\u304b\u308b\u30b5\u30f3\u30d7\u30eb\u3002<\/p>\n<p><!--more--><\/p>\n<pre lang=\"java\" line=\"1\">\r\nimport processing.video.*;\r\n\r\nCapture video;    \/\/\u30ad\u30e3\u30d7\u30c1\u30e3\u7528\u5909\u6570\r\nint[] previousFrame;    \/\/\u4e00\u3064\u524d\u306e\u30d5\u30ec\u30fc\u30e0\r\nint pixelNum;    \/\/\u30ad\u30e3\u30d7\u30c1\u30e3\u753b\u9762\u306e\u7dcf\u30d4\u30af\u30bb\u30eb\u6570\r\nint noiseFilter = 50;    \/\/\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\nint reduction = 8;    \/\/\u753b\u9762\u306b\u5bfe\u3057\u3066\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u6620\u50cf\u306e\u7e2e\u5c0f\u5ea6\u5408\u3044 8\u306e\u5834\u5408\u306f\u3001\u30ad\u30e3\u30d7\u30c1\u30e3\u753b\u50cf\u304c\u753b\u9762\u306e1\/8\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308b\r\nint movementSum; \/\/\u4e00\u3064\u306e\u30d5\u30ec\u30fc\u30e0\u3067\u306e\u52d5\u4f5c\u91cf\r\nfloat[] eSize;    \/\/\u5186\u306e\u30b5\u30a4\u30ba\r\nfloat[] eSpeed;    \/\/\u5186\u306e\u62e1\u5927\u306e\u30b9\u30d4\u30fc\u30c9\r\nfloat[] eAlpha;    \/\/\u5186\u306e\u900f\u660e\u5ea6\r\nfloat[] eAlphaSpeed;    \/\/\u5186\u306e\u900f\u660e\u5ea6\u306e\u30b9\u30d4\u30fc\u30c9\r\nint[] eFlag;    \/\/\u5186\u306e\u900f\u660e\u5ea6\u304c0\u306b\u306a\u3063\u305f\u304b\u3069\u3046\u304b\u3092\u5224\u65ad\u3059\u308b\u305f\u3081\u306e\u30d5\u30e9\u30c3\u30b0\r\n\r\nvoid setup() {\r\n  \/\/ 640 x 480\u304c\u5927\u304d\u3059\u304e\u3066\u9045\u304b\u3063\u305f\u3089\u3001320 x 240\u306b\u5909\u66f4\u3059\u308b\r\n  size(640, 480);\r\n\r\n  \/\/\u753b\u9762\u30b5\u30a4\u30ba\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u753b\u50cf\u3092\u751f\u6210\u3002\u753b\u9762\u304c\u30b3\u30de\u843d\u3061\u3059\u308b\u3088\u3046\u3060\u3063\u305f\u3089\u3001\r\n  \/\/\u4e00\u756a\u53f3\u306e\u30d5\u30ec\u30fc\u30e0\u30ec\u30fc\u30c8\u3092\u4e0a\u3052\u308b\u3002\r\n  \/\/\u3053\u306e\u5834\u5408\u306f\u300180x60\u306e\u30ad\u30e3\u30d7\u30c1\u30e3\u753b\u50cf\u300190\u30d5\u30ec\u30fc\u30e0\uff0f\u79d2\u3092\u8a2d\u5b9a\r\n  video = new Capture(this, width\/reduction, height\/reduction, 90);\r\n  pixelNum = video.width * video.height;    \/\/\u30ad\u30e3\u30d7\u30c1\u30e3\u753b\u50cf\u306e\u7dcf\u30d4\u30af\u30bb\u30eb\u6570\r\n  previousFrame = new int[pixelNum];    \/\/\u4e00\u3064\u524d\u306e\u30d5\u30ec\u30fc\u30e0\uff08\u914d\u5217\uff09\r\n  eSize = new float[pixelNum];    \/\/\u5186\u306e\u5927\u304d\u3055\r\n  eSpeed = new float[pixelNum];    \/\/\u5186\u306e\u62e1\u5927\u30b9\u30d4\u30fc\u30c9\r\n  eAlpha = new float[pixelNum];    \/\/\u5186\u306e\u900f\u660e\u5ea6\r\n  eAlphaSpeed = new float[pixelNum];    \/\/\u5186\u306e\u900f\u660e\u5316\u306e\u30b9\u30d4\u30fc\u30c9\r\n  eFlag = new int[pixelNum];    \/\/\u5186\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u72b6\u614b\u304b\u305d\u3046\u3067\u306a\u3044\u304b\u3092\u5224\u65ad\u3059\u308b\u30d5\u30e9\u30c3\u30b0\r\n\r\n  \/\/\u5186\u306e\u5c5e\u6027\u306e\u521d\u671f\u5316\r\n  for(int i = 0; i < pixelNum; i ++){\r\n    eSize[i] = 0.0;\r\n    eSpeed[i] = 1.0;\r\n    eAlpha[i] = 200.0;\r\n    eAlphaSpeed[i] = 2.0;\r\n    eFlag[i] = 0;\r\n  }\r\n  loadPixels();    \/\/\u753b\u9762\u306b\u753b\u50cf\u306e\u30d4\u30af\u30bb\u30eb\u3092\u5c55\u958b\r\n}\r\n\r\nvoid draw() {\r\n  background(0);\r\n  float m = millis();    \/\/\u6642\u9593\u3092\u30ab\u30a6\u30f3\u30c8\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    movementSum = 0; \/\/\u4e00\u3064\u306e\u30d5\u30ec\u30fc\u30e0\u3067\u306e\u52d5\u4f5c\u91cf\r\n\r\n    \/\/1\u30d4\u30af\u30bb\u30eb\u3054\u3068\u306b\u8272\u3092\u8abf\u3079\u308b\u3002\r\n    for (int y = 0; y < video.height; y ++) {\r\n      for (int x = 0; x < video.width; x ++) {\r\n        \/\/\u30d3\u30c7\u30aa\u306e\u30d4\u30af\u30bb\u30eb\u3092\u629c\u304d\u51fa\u3059\r\n        int currColor = video.pixels[y*video.width + x];\r\n        int prevColor = previousFrame[y*video.width + x];\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        \/\/\u4ee5\u4e0b\u306e\u6761\u4ef6\u6587\u306f3\u79d2\u5f8c\u306b\u6709\u52b9\u306b\u306a\u308b\r\n        if(diffR + diffG + diffB > noiseFilter && eFlag[y*video.width + x] == 0 && m > 3*1000){\r\n          eFlag[y*video.width + x] = 1;    \/\/\u30d5\u30e9\u30c3\u30b0\u30921\u306b\u3059\u308b\uff08\u5186\u304c\u518d\u751f\u4e2d\uff09\r\n          movementSum ++;\r\n          \r\n          \/\/\u4ee5\u4e0b\u306e4\u884c\u306e\u30b3\u30fc\u30c9\u306f\u52d5\u3044\u305f\u3068\u3053\u308d\u306b\u30e9\u30a4\u30f3\u3092\u767a\u751f\u3055\u305b\u308b\u30b3\u30fc\u30c9\u3067\u3042\u308b\uff08\u5de6\u53f3\u3092\u53cd\u8ee2\u3055\u305b\u3066\u3044\u308b\uff09\r\n          float lineSize = (float)(diffR + diffG + diffB)\/(255*3)*20.0;\r\n          stroke(currR, 100, 255, 80);\r\n          line(((video.width-x)-lineSize)*reduction, y*reduction, ((video.width-x)+lineSize)*reduction, y*reduction);\r\n          stroke(255, 100, currB, 80);\r\n          line((video.width-x)*reduction, (y-lineSize\/2)*reduction, (video.width-x)*reduction, (y+lineSize\/2)*reduction);\r\n        }\r\n        \r\n        \/\/\u900f\u660e\u5ea6\uff08Alpha\uff09\u304c0.0\u672a\u6e80\u306b\u306a\u3089\u306a\u3044\u9650\u308a\u306f\u3001\u5186\u306f\u3072\u305f\u3059\u3089\u5927\u304d\u304f\u306a\u308a\u3001\u900f\u660e\u5ea6\u306f\u3072\u305f\u3059\u3089\u4e0b\u304c\u308b\r\n        if(eFlag[y*video.width + x] == 1 && eAlpha[y*video.width + x] >= 0.0){\r\n          eSize[y*video.width + x] += eSpeed[y*video.width + x];\r\n          eAlpha[y*video.width + x] -= eAlphaSpeed[y*video.width + x];\r\n\r\n          noStroke();\r\n          fill(currR, currG, currB, (int)(eAlpha[y*video.width + x]));\r\n          ellipse((video.width-x)*reduction, y*reduction, eSize[y*video.width + x],  eSize[y*video.width + x]);\r\n\r\n        }    \/\/\u900f\u660e\u5ea6\uff08Alpha\uff09\u304c0.0\u672a\u6e80\u306b\u306a\u3063\u305f\u3089\u3001\u5186\u306e\u5c5e\u6027\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\r\n        else if(eFlag[y*video.width + x] == 1 && eAlpha[y*video.width + x] < 0.0){\r\n          eSize[y*video.width + x] = 0.0;\r\n          eAlpha[y*video.width + x] = 100.0;\r\n          eFlag[y*video.width + x] = 0;\r\n        }\r\n\r\n        previousFrame[y*video.width + x] = currColor;    \/\/\u73fe\u5728\u306e\u8272\u3092\u4e00\u3064\u524d\u306e\u30d5\u30ec\u30fc\u30e0\u306e\u8272\u3068\u3057\u3066\u4fdd\u5b58\r\n      }\r\n    }\r\n    textSize(12);  \/\/\u30c6\u30ad\u30b9\u30c8\u306e\u30b5\u30a4\u30ba\r\n    fill(255);\r\n    text(movementSum, 30,30);  \/\/\u5909\u5316\u3057\u305f\u30d4\u30af\u30bb\u30eb\u306e\u7dcf\u6570\u3092\u753b\u9762\u306b\u30d7\u30ea\u30f3\u30c8\r\n  }\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4eba\u304c\u52d5\u3044\u305f\u5f8c\u306b\u3044\u308d\u3044\u308d\u306a\u30a8\u30d5\u30a7\u30af\u30c8\u304c\u304b\u304b\u308b\u30b5\u30f3\u30d7\u30eb\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-1853","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\/1853","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=1853"}],"version-history":[{"count":3,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/posts\/1853\/revisions"}],"predecessor-version":[{"id":2445,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/posts\/1853\/revisions\/2445"}],"wp:attachment":[{"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/media?parent=1853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/categories?post=1853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/r-dimension.xsrv.jp\/classes_j\/wp-json\/wp\/v2\/tags?post=1853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}