#ifndef _TEST_APP\n#define _TEST_APP\n\n#include "ofMain.h"\n#include "ofxVectorMath.h"\n#include "ofxOpenCv.h"\n\n\/\/\u8272\u306e\u57fa\u672c\u7684\u306a\u60c5\u5831\u3092\u6301\u3063\u305f\u30af\u30e9\u30b9\u3092\u4f5c\u308a\u307e\u3059\u3002\nclass Color {\npublic:\n float hue, sat, bri;\n ofxVec2f pos;\n};\n\n\nclass testApp : public ofBaseApp{\n\n public:\n \/\/\u3053\u306e\u8fba\u306f\u3044\u3064\u3082\u901a\u308a\n void setup();\n void update();\n void draw();\n\n void keyPressed (int key);\n void keyReleased(int key);\n void mouseMoved(int x, int y );\n void mouseDragged(int x, int y, int button);\n void mousePressed(int x, int y, int button);\n void mouseReleased(int x, int y, int button);\n void windowResized(int w, int h);\n\n\n \/\/\u30ab\u30e1\u30e9\u306e\u6620\u50cf\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\n ofVideoGrabber vidGrabber;\n\n \/\/\u30ab\u30e1\u30e9\u306e\u5e45\u3068\u9ad8\u3055\n int camWidth;\n int camHeight;\n\n \/\/\u3082\u3068\u3082\u3068\u306e\u6620\u50cf\u60c5\u5831\n ofxCvColorImage colorImg;\n\n \/\/HSV\u7cfb\u306b\u5909\u63db\u3057\u305f\u6620\u50cf\u60c5\u5831\n ofxCvColorImage colorImgHSV;\n\n \/\/HSV\u7cfb\u306e\u8272\u76f8\u3001\u5f69\u5ea6\u3001\u660e\u5ea6\u306e\u30de\u30c3\u30d7\n ofxCvGrayscaleImage hueImg;\n ofxCvGrayscaleImage satImg;\n ofxCvGrayscaleImage briImg;\n\n \/\/\u8272\u3092\u8ffd\u8de1\u3057\u3066\u8f2a\u90ed\u3092\u51fa\u3059\u305f\u3081\u306e\u6620\u50cf\u60c5\u5831\n ofxCvGrayscaleImage reds;\n\n \/\/\u8ffd\u8de1\u3059\u308b\u8272\u3067\u3059\u3002\n Color one;\n\n \/\/\u3082\u3068\u306e\u6620\u50cf\u60c5\u5831\u306e\u30d4\u30af\u30bb\u30eb\u306e\u5f69\u5ea6\u3068\u660e\u5ea6\u304c\n \/\/\u6307\u5b9a\u3057\u305f\u8272\u306b\u8fd1\u3051\u308c\u3070255\u3092\u4ee3\u5165\u3001\u9060\u3051\u308c\u30700\u3092\u4ee3\u5165\n unsigned char * colorTrackedPixelsRed;\n\n \/\/\u4e8c\u5024\u753b\u50cf\n ofTexture trackedTextureRed;\n\n \/\/\u8f2a\u90ed\u3092\u5224\u5225\u3057\u3066\u304f\u308c\u308b\u30e1\u30c1\u30e3\u30af\u30c1\u30e3\u4fbf\u5229\u306a\u3084\u3064\u3067\u3059\u3002\n ofxCvContourFinder finderRed;\n};\n\n#endif<\/code><\/pre><\/div>\n\n\n\n#include "testApp.h"\n\n\/\/--------------------------------------------------------------\nvoid testApp::setup(){\n \/\/\u6700\u521d\u306f\u8272\u304c\u539f\u70b9\u306b\u3042\u308b\u3053\u3068\u306b\u3057\u307e\u3059\n one.pos = ofxVec2f(0,0);\n\n \/\/\u30ab\u30e1\u30e9\u306e\u5927\u304d\u3055\u3092\u6307\u5b9a\n camWidth = 320;\n camHeight = 240;\n\n \/\/\u305d\u308c\u305e\u308c\u306e\u6620\u50cf\u60c5\u5831\u306e\u5927\u304d\u3055\u3092\u6307\u5b9a\u3057\u3066\u3042\u3052\u307e\u3059\u3002\n colorImg.allocate(camWidth, camHeight);\n colorImgHSV.allocate(camWidth, camHeight);\n\n hueImg.allocate(camWidth, camHeight);\n satImg.allocate(camWidth, camHeight);\n briImg.allocate(camWidth, camHeight);\n\n reds.allocate(camWidth, camHeight);\n\n \/\/\u4e8c\u5024\u753b\u50cf\u3092\u4f5c\u308b\u305f\u3081\u306e\u914d\u5217\u306e\u5927\u304d\u3055\u3092\u6307\u5b9a\n colorTrackedPixelsRed =new unsigned char [camWidth*camHeight];\n\n \/\/\u4e8c\u5024\u753b\u50cf\u306e\u5927\u304d\u3055\n trackedTextureRed.allocate(camWidth, camHeight, GL_LUMINANCE);\n\n \/\/Grabber\u306e\u300c\u4f55\u304b\u300d\u3068\u5927\u304d\u3055\u8a2d\u5b9a\n \/\/setVerbose\u3063\u3066\u306a\u3093\u3060\u308d\uff1f Verbose:\u5197\u9577\u306a\u3001\u8a00\u8449\u6570\u306e\u591a\u3044\n vidGrabber.setVerbose(true);\n vidGrabber.initGrabber(camWidth, camHeight);\n}\n\n\/\/--------------------------------------------------------------\nvoid testApp::update(){\n \/\/\u6620\u50cf\u3092\u53d6\u5f97\uff01\n vidGrabber.grabFrame();\n\n \/\/colorImg\u306e\u4e2d\u8eab\u3092\u30d4\u30af\u30bb\u30eb\u3054\u3068\u306b\u6307\u5b9a\n colorImg.setFromPixels(vidGrabber.getPixels(), camWidth, camHeight);\n\n \/\/HSV\u7cfb\u306b\u5909\u63db\n colorImgHSV = colorImg;\n colorImgHSV.convertRgbToHsv();\n\n \/\/\u8272\u76f8\u3001\u5f69\u5ea6\u3001\u660e\u5ea6\u306b\u30de\u30c3\u30d4\u30f3\u30b0\n colorImgHSV.convertToGrayscalePlanarImages(hueImg, satImg, briImg);\n\n \/\/\u3053\u3053\u304c\u4f55\u3084\u3063\u3066\u3093\u306e\u304b\u5206\u304b\u3089\u3093\u3002\n hueImg.flagImageChanged();\n satImg.flagImageChanged();\n briImg.flagImageChanged();\n\n \/\/\u30d4\u30af\u30bb\u30eb\u306e\u914d\u5217\u3092\u305d\u308c\u305e\u308c\u306b\u4f5c\u6210\n unsigned char * huePixels = hueImg.getPixels();\n unsigned char * satPixels = satImg.getPixels();\n unsigned char * briPixels = briImg.getPixels();\n\n \/\/\u30d4\u30af\u30bb\u30eb\u306e\u6570\n int nPixels = camWidth*camHeight;\n\n \/\/\u30d4\u30af\u30bb\u30eb\u306e\u8272\u304c\u6307\u5b9a\u3057\u305f\u8272\u3068\u8272\u76f8\u3068\u5f69\u5ea6\u304c\u8fd1\u3051\u308c\u3070\u3001\n \/\/colorTrackedPixelsRed\u306b255\u3092\u3001\u9060\u3051\u308c\u30700\u3092\u4ee3\u5165\u3002\n for (int i=0; i < nPixels; i++) {\n if ( (huePixels[i] >=one.hue-12 && huePixels[i] <= one.hue + 12) &&\n (satPixels[i] >=one.sat-24 && satPixels[i] <=one.sat+200)){\n colorTrackedPixelsRed[i] = 255;\n }else {\n colorTrackedPixelsRed[i]=0;\n }\n\n }\n\n \/\/colorTrackedPixelsRed\u3092\u3082\u3068\u306breds\u3092\u4f5c\u6210\n \/\/reds\u306f\u8f2a\u90ed\u7dda\u3092\u6c42\u3081\u308b\u305f\u3081\u3060\u3051\u306b\u3042\u308b\u306e\u304b\u306a\uff1f\n reds.setFromPixels(colorTrackedPixelsRed, camWidth, camHeight);\n\n \/\/\u8f2a\u90ed\u7dda\u3092\u898b\u3064\u3051\u308b\n finderRed.findContours(reds, 10, nPixels\/3, 1, false, true);\n\n \/\/colorTrackedPixelsRed\u3092\u3082\u3068\u306btrackedTextureRed\u3092\u4f5c\u6210\n \/\/\u3053\u308c\u304c\u4e8c\u5024\u753b\u50cf\u306b\u306a\u3063\u3066\u308b\u3063\u307d\u3044\n trackedTextureRed.loadData(colorTrackedPixelsRed,\n camWidth, camHeight, GL_LUMINANCE);\n\n \/\/\u8ffd\u8de1\u3059\u308b\u8272\u306e\u4f4d\u7f6e\u3092\u4e2d\u5fc3\u306b\u3042\u308f\u305b\u308b\n if (finderRed.blobs.size() > 0) {\n one.pos = ofxVec2f(finderRed.blobs[0].centroid.x,\n finderRed.blobs[0].centroid.y);\n }\n}\n\n\/\/--------------------------------------------------------------\nvoid testApp::draw(){\n \/\/\u80cc\u666f\u8272\u3092\u6307\u5b9a\n ofBackground(100, 100, 100);\n\n ofSetColor(0xffffff);\n\n \/\/\u5143\u6620\u50cf\u3092\u8868\u793a\n vidGrabber.draw(0, 0);\n\n \/\/HSV\u7cfb\u306b\u5909\u63db\u3057\u305f\u3082\u306e\u3092\u8868\u793a\n colorImgHSV.draw(340, 0);\n\n \/\/\u4e8c\u5024\u753b\u50cf\u3092\u8868\u793a\n trackedTextureRed.draw(20, 300);\n ofDrawBitmapString("red", 20, 280);\n\n \/\/\u5143\u6620\u50cf\u306b\u8f2a\u90ed\u7dda\u3092\u8868\u793a\n finderRed.draw();\n\n \/\/\u4e8c\u5024\u753b\u50cf\u306e\u65b9\u306b\u8f2a\u90ed\u7dda\u8868\u793a\n glPushMatrix();\n glTranslatef(20, 300, 0);\n finderRed.draw();\n glPopMatrix();\n\n \/\/\u8ffd\u8de1\u3059\u308b\u8272\u306e\u4f4d\u7f6e\u3092\u8868\u793a\n if (finderRed.blobs.size() > 0) {\n char tempStr1[255];\n sprintf(tempStr1, "x:%fny:%f",\n finderRed.blobs[0].centroid.x,\n finderRed.blobs[0].centroid.y);\n ofDrawBitmapString(tempStr1, 20, 250);\n }\n}\n\n\/\/--------------------------------------------------------------\nvoid testApp::mousePressed(int x, int y, int button){\n unsigned char * huePixels = hueImg.getPixels();\n unsigned char * satPixels = satImg.getPixels();\n unsigned char * briPixels = briImg.getPixels();\n\n \/\/\u30af\u30ea\u30c3\u30af\u3057\u305f\u5834\u6240\u306e\u8272\u3092\u8ffd\u8de1\u3059\u308b\u8272\u306b\u8a2d\u5b9a\u3002\n x=MIN(x,hueImg.width-1);\n y=MIN(y,hueImg.height-1);\n\n if (button==0) {\n one.hue = huePixels[x+(y*hueImg.width)];\n one.sat = satPixels[x+(y*satImg.width)];\n one.bri = briPixels[x+(y*briImg.width)];\n }\n}<\/code><\/pre><\/div>\n\n\n\ntestApp::update()<\/code>\u306e\u6700\u5f8c\u306b\u3042\u308bone.pos<\/code>\u306b\u8272\u3092\u8ffd\u8de1\u3057\u305f\u7d50\u679c\u306e\u5ea7\u6a19\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<\/span>\u5fdc\u7528\u4f8b<\/span><\/h3>\n\n\n\n\u8272\u3054\u3068\u306b\u30b7\u30f3\u30bb\u30b5\u30a4\u30b6\u30fc\u306e\u97f3\u3001\u30c9\u30e9\u30e0\u30d1\u30bf\u30fc\u30f3\u3001\u30d5\u30a3\u30eb\u30bf\u30fc\u3068\u3044\u3046\u5f79\u5272\u3092\u6301\u305f\u305b\u3066\u3001\u30ab\u30e1\u30e9\u4e0a\u3067\u5404\u8272\u304c\u3069\u3053\u306b\u3042\u308b\u306e\u304b\u3092\u89e3\u6790\u3057\u3001\u305d\u308c\u306b\u5fdc\u3058\u3066\u97f3\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n\n\n\n