Index: addons/ofxNCore/src/Controls/gui.h =================================================================== --- addons/ofxNCore/src/Controls/gui.h (revision 176) +++ addons/ofxNCore/src/Controls/gui.h (working copy) @@ -106,6 +106,7 @@ srcPanel->addButton(appPtr->sourcePanel_previousCam, "Previous Camera", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger, ""); srcPanel->addButton(appPtr->sourcePanel_nextCam, "Next Camera", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger, ""); srcPanel->addButton(appPtr->sourcePanel_video, "Use Video", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, ""); + srcPanel->mObjHeight = 85; srcPanel->mObjWidth = 319; srcPanel->mObjects[0]->mObjX = 110; @@ -118,8 +119,58 @@ srcPanel->mObjects[4]->mObjX = 230; srcPanel->mObjects[4]->mObjY = 42; srcPanel->mObjects[5]->mObjY = 65; - srcPanel->adjustToNewContent(100, 0); + + int srcYOffset = 0; + if (appPtr->hsvFilter) { + const int hsvW = 72; + const int hsvM = 5; + int panelIdx = 6; + + srcPanel->addButton(appPtr->hsvFilter_use, "Color T.", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, appPtr->hsvFilter->isEnabled() ? kofxGui_Button_On : kofxGui_Button_Off, kofxGui_Button_Switch, ""); + srcPanel->mObjects[panelIdx]->mObjX = 90; + srcPanel->mObjects[panelIdx]->mObjY = 65; + + int hsvX = 165, hsvY = 55; + panelIdx++; + srcPanel->addSlider(appPtr->hsvFilter_hue, "H", hsvW, 13, 0.f, HSVColorFilter::HUE_LIMIT, appPtr->hsvFilter->getHue(), kofxGui_Display_Int, HSVColorFilter::HUE_LIMIT); + srcPanel->mObjects[panelIdx]->mObjX = hsvX; + srcPanel->mObjects[panelIdx]->mObjY = hsvY; + hsvX += hsvW + hsvM; + panelIdx++; + srcPanel->addSlider(appPtr->hsvFilter_hueRange, "H Range", hsvW, 13, 0.f, HSVColorFilter::HUE_LIMIT, appPtr->hsvFilter->getHueRange(), kofxGui_Display_Int, HSVColorFilter::HUE_LIMIT); + srcPanel->mObjects[panelIdx]->mObjX = hsvX; + srcPanel->mObjects[panelIdx]->mObjY = hsvY; + hsvX += hsvW + hsvM; + + hsvX = 5; + hsvY = 85; + panelIdx++; + srcPanel->addSlider(appPtr->hsvFilter_satMin, "S Min", hsvW, 13, 0.f, 255, appPtr->hsvFilter->getSaturationMin(), kofxGui_Display_Int, 255); + srcPanel->mObjects[panelIdx]->mObjX = hsvX; + srcPanel->mObjects[panelIdx]->mObjY = hsvY; + hsvX += hsvW + hsvM; + panelIdx++; + srcPanel->addSlider(appPtr->hsvFilter_satMax, "S Max", hsvW, 13, 0.f, 255.f, appPtr->hsvFilter->getSaturationMax(), kofxGui_Display_Int, 255); + srcPanel->mObjects[panelIdx]->mObjX = hsvX; + srcPanel->mObjects[panelIdx]->mObjY = hsvY; + hsvX += hsvW + hsvM * 2; + + panelIdx++; + srcPanel->addSlider(appPtr->hsvFilter_valMin, "V Min", hsvW, 13, 0.f, 255, appPtr->hsvFilter->getValueMin(), kofxGui_Display_Int, 255); + srcPanel->mObjects[panelIdx]->mObjX = hsvX; + srcPanel->mObjects[panelIdx]->mObjY = hsvY; + hsvX += hsvW + hsvM; + panelIdx++; + srcPanel->addSlider(appPtr->hsvFilter_valMax, "V Max", hsvW, 13, 0.f, 255.f, appPtr->hsvFilter->getValueMax(), kofxGui_Display_Int, 255); + srcPanel->mObjects[panelIdx]->mObjX = hsvX; + srcPanel->mObjects[panelIdx]->mObjY = hsvY; + + srcYOffset = -195; + } + srcPanel->adjustToNewContent(100, srcYOffset); + + //Background Image ofxGuiPanel* bkPanel1 = controls->addPanel(appPtr->backgroundPanel, "Background", 86, 487, 10, 7); bkPanel1->addButton(backgroundPanel_remove, "Remove BG (b)", 10, 10, kofxGui_Button_Off, kofxGui_Button_Trigger, ""); @@ -332,6 +383,48 @@ } } break; + case hsvFilter_use: + if (appPtr->hsvFilter) { + appPtr->hsvFilter->setEnabled(*(bool*)data); + filter->bLearnBakground = true; + } + break; + case hsvFilter_hue: + if (appPtr->hsvFilter) { + appPtr->hsvFilter->setHue(0, *(float*)data); + //filter->bLearnBakground = true; + } + break; + case hsvFilter_hueRange: + if (appPtr->hsvFilter) { + appPtr->hsvFilter->setHueRange(0, *(float*)data); + //filter->bLearnBakground = true; + } + break; + case hsvFilter_satMin: + if (appPtr->hsvFilter) { + appPtr->hsvFilter->setSaturationMin(0, *(float*)data); + //filter->bLearnBakground = true; + } + break; + case hsvFilter_satMax: + if (appPtr->hsvFilter) { + appPtr->hsvFilter->setSaturationMax(0, *(float*)data); + //filter->bLearnBakground = true; + } + break; + case hsvFilter_valMin: + if (appPtr->hsvFilter) { + appPtr->hsvFilter->setValueMin(0, *(float*)data); + //filter->bLearnBakground = true; + } + break; + case hsvFilter_valMax: + if (appPtr->hsvFilter) { + appPtr->hsvFilter->setValueMax(0, *(float*)data); + //filter->bLearnBakground = true; + } + break; case propertiesPanel_settings: if(length == sizeof(bool)) { Index: addons/ofxNCore/src/Filters/HSVColorFilter.cpp =================================================================== --- addons/ofxNCore/src/Filters/HSVColorFilter.cpp (revision 0) +++ addons/ofxNCore/src/Filters/HSVColorFilter.cpp (revision 0) @@ -0,0 +1,220 @@ +/* + * HSVColorFilter.cpp + * + * Created by Luiz Geovani Vier on 9/24/09. + * Copyright 2009 pixtream. All rights reserved. + * http://www.pixtream.com.br + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include "HSVColorFilter.h" + +const int HSVColorFilter::HUE_LIMIT = 180; + +class HSVColorFilterUI +{ + HSVColorFilter *filter; + ofxCvColorImage hueImg; + ofxCvColorImage inImg; + unsigned char* pixels; + HSVColorFilterUI(HSVColorFilter *filter) : filter(filter), hueImg(), inImg(), pixels(new unsigned char[3]) { + hueImg.allocate(1, 1); + } + ~HSVColorFilterUI() { + delete[] pixels; + } + + void draw() { + + if (!inImg.bAllocated) { + inImg.allocate(filter->hsvImage->width, filter->hsvImage->height); + } + inImg.setFromPixels((unsigned char*)filter->hsvImage->imageData, filter->hsvImage->width, filter->hsvImage->height); + inImg.convertHsvToRgb(); + inImg.draw(40, 30, filter->hsvImage->width, filter->hsvImage->height); + + pixels[0] = filter->getHueMin(); + pixels[1] = 255; + pixels[2] = 255; + + hueImg.setFromPixels(pixels, 1, 1); + hueImg.convertHsvToRgb(); + const int x = 320, y = 250, w = 20, h = 20; + hueImg.draw(x, y, w, h); + + pixels[0] = filter->getHueMax(); + hueImg.setFromPixels(pixels, 1, 1); + hueImg.convertHsvToRgb(); + hueImg.draw(x + w, y, w, h); + + ofSetColor(255, 255, 255); + ofNoFill(); + ofRect(x, y, w*2, h); + } + friend class HSVColorFilter; +}; + +HSVColorFilter::HSVColorFilter() + : enabled(true), smoothAmt(0), configArray(), trackedColorsCount(1) + , pixelCount(0), hsvImage(0) + , ui(new HSVColorFilterUI(this)) +{ + std::cout << "HSVColorFilter created." << std::endl; +} + +HSVColorFilter::~HSVColorFilter() +{ + delete ui; + if (hsvImage) + cvReleaseImage(&hsvImage); +} + +void HSVColorFilter::processFrame(ofxCvColorImage &in, ofxCvGrayscaleImage &out) +{ + IplImage *cvIn = in.getCvImage(); + + if (!hsvImage) { + // create an image to hold the HSV pixels + hsvImage = cvCreateImage(cvSize(cvIn->width,cvIn->height), cvIn->depth, 3); + hsvImage->origin = cvIn->origin; + pixelCount = hsvImage->width * hsvImage->height * hsvImage->nChannels; + } + + // setup + for (int i = 0; i < trackedColorsCount; i++) { + ConfigItem &cfg = configArray[i]; + if (cfg.recalcNeeded) { + std::cout << "HSVColorFilter conf[" << i << "] has changed" << std::endl; + cfg.recalc(); + } + } + + const int cvt = CV_RGB2HSV; + if (smoothAmt > 0) { + // apply cvSmooth to eliminate noise + cvSmooth(cvIn, hsvImage, CV_BLUR, smoothAmt * 2 + 1); + // Convert to HSV + cvCvtColor(hsvImage, hsvImage, cvt); + } else { + // Convert to HSV + cvCvtColor(cvIn, hsvImage, cvt); + } + + unsigned char* inPixels = (unsigned char*)hsvImage->imageData; + char* outPixels = out.getCvImage()->imageData; + + const float hWeight = 85.f * 2.f; + const float svWeight = 85.f/2.f; + + + // Filter the image + for (int i = 0, j = 0, outIdx = 0; i < pixelCount; i+=hsvImage->nChannels, outIdx++) { + for (int j = 0; j < trackedColorsCount; j++) { + outPixels[outIdx] = configArray[j].toGrayPixel(inPixels[i], inPixels[i+1], inPixels[i+2]); + if (outPixels[outIdx] != 0) + break; + } + } + +} + +void HSVColorFilter::draw() +{ + ui->draw(); +} + +HSVColorFilter::Color HSVColorFilter::getColorAt(int x, int y) +{ + if (!hsvImage) { + return Color(-1,-1,-1); + } + unsigned char* pix = (unsigned char*)hsvImage->imageData; + int idx = y * hsvImage->width * hsvImage->nChannels; + idx += x * hsvImage->nChannels; + int h = pix[idx++]; + int s = pix[idx++]; + int v = pix[idx++]; + return Color(h, s, v); +} + +void HSVColorFilter::ConfigItem::recalc() { + recalcNeeded = false; + min.h = center.h - (range.h/2); + max.h = center.h + (range.h/2); + hueFlipped = false; + if (min.h < 0) { + int tmp = min.h + HUE_LIMIT; + min.h = max.h; + max.h = tmp; + hueFlipped = true; + } else if (max.h > HUE_LIMIT) { + int tmp = max.h - HUE_LIMIT; + max.h = min.h; + min.h = tmp; + hueFlipped = true; + } + range.s = max.s - min.s; + range.v = max.v - min.v; + center.s = min.s + (range.s / 2); + center.v = min.v + (range.v / 2); + + std::cout << "min.h: " << min.h << ", max.h: " << max.h << ", hueFlipped: " << hueFlipped << std::endl; + std::cout << "min.s: " << min.s << ", max.s: " << max.s << std::endl; + std::cout << "min.v: " << min.v << ", max.v: " << max.v << std::endl; +} + + +int HSVColorFilter::ConfigItem::toGrayPixel(int h, int s, int v) +{ + if (s >= min.s && s <= max.s + && v >= min.v && v <= max.v) { + if ((!hueFlipped && (h >= min.h && h <= max.h)) + || (hueFlipped && (h >= max.h || h <= min.h))) { + int hCenter = center.h; + if (hueFlipped) { + const int halfHueLimit = HSVColorFilter::HUE_LIMIT / 2; + if (h < halfHueLimit && hCenter > halfHueLimit) { + hCenter -= HSVColorFilter::HUE_LIMIT; + } else if (h > halfHueLimit && hCenter < halfHueLimit) { + hCenter += HSVColorFilter::HUE_LIMIT; + } + } + const float hWeight = 85.f * 2.f; + const float svWeight = 85.f / 2.f; + int oh = ((range.h - abs(h - hCenter)) / (float)range.h) * hWeight; + int os = ((range.s - abs(s - center.s)) / (float)range.s) * svWeight; + int ov = ((range.v - abs(v - center.v)) / (float)range.v) * svWeight; + //std::cout << "in h: " << h << ", s: " << s << ", v: " << v << std::endl; + //std::cout << "out h: " << oh << ", s: " << os << ", v: " << ov << std::endl; + return oh + os + ov; + } + } + return 0; +} + +/* +// test +int main() { + + HSVColorFilter::ConfigItem cfg; + cfg.center.h = 119; + cfg.range.h = 20; + cfg.min.s = 40; + cfg.max.s = 200; + cfg.min.v = 100; + cfg.max.v = 250; + cfg.recalc(); + + + unsigned char* inPixels = new unsigned char[3]; + inPixels[0] = 30; + inPixels[1] = 100; + inPixels[2] = 150; + + int i = 0; + std::cout << "gray: " << cfg.toGrayPixel(inPixels[i], inPixels[i+1], inPixels[i+2]) << std::endl; +} +*/ Index: addons/ofxNCore/src/Filters/HSVColorFilter.h =================================================================== --- addons/ofxNCore/src/Filters/HSVColorFilter.h (revision 0) +++ addons/ofxNCore/src/Filters/HSVColorFilter.h (revision 0) @@ -0,0 +1,93 @@ +/* + * HSVColorFilter.h + * + * Created by Luiz Geovani Vier on 9/24/09. + * Copyright 2009 pixtream. All rights reserved. + * http://www.pixtream.com.br + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#ifndef __HSVColorFILTER__ +#define __HSVColorFILTER__ + +#include "ofxOpenCv.h" + +#define TRACKED_COLORS_LIMIT 10 +class HSVColorFilterUI; + +class HSVColorFilter +{ +public: + static const int HUE_LIMIT; + + struct Color { + int h,s,v; + Color(int h = 0, int s = 0, int v = 0) : h(h), s(s), v(v) {} + }; + + struct ConfigItem { + Color center; + Color range; + Color min; + Color max; + bool hueFlipped; + bool recalcNeeded; + ConfigItem() : hueFlipped(false), recalcNeeded(true) {} + void recalc(); + inline int toGrayPixel(int h, int s, int v); + }; + +protected: + // parameters + bool enabled; + int smoothAmt; + ConfigItem configArray[TRACKED_COLORS_LIMIT]; + + // local + int trackedColorsCount; + IplImage* hsvImage; + int pixelCount; + HSVColorFilterUI *ui; + + inline int getHueMin(int idx = 0) { return configArray[idx].min.h; } + inline int getHueMax(int idx = 0) { return configArray[idx].max.h; } + +public: + HSVColorFilter(); + virtual ~HSVColorFilter(); + + inline bool isEnabled() { return enabled; } + inline void setEnabled(bool b) { enabled = b; } + + inline int getSmoothAmt() { return smoothAmt; } + inline void setSmoothAmt(int val) { smoothAmt = val; } + + inline int getTrackedColorsCount() { return trackedColorsCount; } + inline void setTrackedColorsCount(int val) { trackedColorsCount = val; } + + inline int getHue(int idx = 0) { return configArray[idx].center.h; } + inline int getHueRange(int idx = 0) { return configArray[idx].range.h; } + inline int getSaturationMin(int idx = 0) { return configArray[idx].min.s; } + inline int getSaturationMax(int idx = 0) { return configArray[idx].max.s; } + inline int getValueMin(int idx = 0) { return configArray[idx].min.v; } + inline int getValueMax(int idx = 0) { return configArray[idx].max.v; } + + inline void setHue(int idx, int val) { configArray[idx].center.h = val; configArray[idx].recalcNeeded = true; } + inline void setHueRange(int idx, int val) { configArray[idx].range.h = val; configArray[idx].recalcNeeded = true; } + inline void setSaturationMin(int idx, int val) { configArray[idx].min.s = val; configArray[idx].recalcNeeded = true; } + inline void setSaturationMax(int idx, int val) { configArray[idx].max.s = val; configArray[idx].recalcNeeded = true; } + inline void setValueMin(int idx, int val) { configArray[idx].min.v = val; configArray[idx].recalcNeeded = true; } + inline void setValueMax(int idx, int val) { configArray[idx].max.v = val; configArray[idx].recalcNeeded = true; } + + void processFrame(ofxCvColorImage &in, ofxCvGrayscaleImage &out); + void draw(); + + Color getColorAt(int x, int y); + + friend class HSVColorFilterUI; +}; + +#endif // __HSVColorFILTER__ Index: addons/ofxNCore/src/Modules/ofxNCoreVision.cpp =================================================================== --- addons/ofxNCore/src/Modules/ofxNCoreVision.cpp (revision 176) +++ addons/ofxNCore/src/Modules/ofxNCoreVision.cpp (working copy) @@ -187,6 +187,16 @@ tmpFlashPort = XML.getValue("CONFIG:NETWORK:TUIOFLASHPORT_OUT", 3000); myTUIO.setup(tmpLocalHost.c_str(), tmpPort, tmpFlashPort); //have to convert tmpLocalHost to a const char* //-------------------------------------------------------------- + // HSV Filter + hsvFilter = new HSVColorFilter; + hsvFilter->setEnabled(XML.getValue("CONFIG:HSVFILTER:ON", false)); + hsvFilter->setSmoothAmt(XML.getValue("CONFIG:HSVFILTER:SMOOTH", 2)); + hsvFilter->setHue(0, XML.getValue("CONFIG:HSVFILTER:HUE:CENTER", 0)); + hsvFilter->setHueRange(0, XML.getValue("CONFIG:HSVFILTER:HUE:RANGE", 20)); + hsvFilter->setSaturationMin(0, XML.getValue("CONFIG:HSVFILTER:SATURATION:MIN", 30)); + hsvFilter->setSaturationMax(0, XML.getValue("CONFIG:HSVFILTER:SATURATION:MAX", 255)); + hsvFilter->setValueMin(0, XML.getValue("CONFIG:HSVFILTER:VALUE:MIN", 30)); + hsvFilter->setValueMax(0, XML.getValue("CONFIG:HSVFILTER:VALUE:MAX", 255)); // END XML SETUP } @@ -226,6 +236,21 @@ XML.setValue("CONFIG:BOOLEAN:TCPMODE", myTUIO.bTCPMode); // XML.setValue("CONFIG:NETWORK:LOCALHOST", myTUIO.localHost); // XML.setValue("CONFIG:NETWORK:TUIO_PORT_OUT",myTUIO.TUIOPort); + + // HSV Filter + if (hsvFilter) { + XML.setValue("CONFIG:HSVFILTER:ON", hsvFilter->isEnabled()); + XML.setValue("CONFIG:HSVFILTER:SMOOTH", hsvFilter->getSmoothAmt()); + XML.setValue("CONFIG:HSVFILTER:HUE:CENTER", hsvFilter->getHue()); + XML.setValue("CONFIG:HSVFILTER:HUE:RANGE", hsvFilter->getHueRange()); + XML.setValue("CONFIG:HSVFILTER:SATURATION:MIN", hsvFilter->getSaturationMin()); + XML.setValue("CONFIG:HSVFILTER:SATURATION:MAX", hsvFilter->getSaturationMax()); + XML.setValue("CONFIG:HSVFILTER:VALUE:MIN", hsvFilter->getValueMin()); + XML.setValue("CONFIG:HSVFILTER:VALUE:MAX", hsvFilter->getValueMax()); + } else { + XML.setValue("CONFIG:HSVFILTER:ON", false); + } + XML.saveFile("config.xml"); } @@ -418,23 +443,35 @@ #ifdef TARGET_WIN32 if(PS3!=NULL){ sourceImg.setFromPixels(PS3->getPixels(), camWidth, camHeight); - //convert to grayscale - processedImg = sourceImg; + if (hsvFilter && hsvFilter->isEnabled()) { + hsvFilter->processFrame(sourceImg, processedImg); + } else { + //convert to grayscale + processedImg = sourceImg; + } } else if(ffmv != NULL){ processedImg.setFromPixels(ffmv->fcImage[ffmv->getDeviceID()].pData, camWidth, camHeight); } else if(vidGrabber != NULL ) { sourceImg.setFromPixels(vidGrabber->getPixels(), camWidth, camHeight); - //convert to grayscale - processedImg = sourceImg; + if (hsvFilter && hsvFilter->isEnabled()) { + hsvFilter->processFrame(sourceImg, processedImg); + } else { + //convert to grayscale + processedImg = sourceImg; + } } else if(dsvl!=NULL) { if(dsvl->getNumByes() != 1){ //if not grayscale sourceImg.setFromPixels(dsvl->getPixels(), camWidth, camHeight); - //convert to grayscale - processedImg = sourceImg; + if (hsvFilter && hsvFilter->isEnabled()) { + hsvFilter->processFrame(sourceImg, processedImg); + } else { + //convert to grayscale + processedImg = sourceImg; + } } else{//if grayscale processedImg.setFromPixels(dsvl->getPixels(), camWidth, camHeight); @@ -454,15 +491,23 @@ getPixels(); #else sourceImg.setFromPixels(vidGrabber->getPixels(), camWidth, camHeight); - //convert to grayscale - processedImg = sourceImg; + if (hsvFilter && hsvFilter->isEnabled()) { + hsvFilter->processFrame(sourceImg, processedImg); + } else { + //convert to grayscale + processedImg = sourceImg; + } #endif } else { sourceImg.setFromPixels(vidPlayer->getPixels(), camWidth, camHeight); - //convert to grayscale - processedImg = sourceImg; + if (hsvFilter && hsvFilter->isEnabled()) { + hsvFilter->processFrame(sourceImg, processedImg); + } else { + //convert to grayscale + processedImg = sourceImg; + } } } @@ -556,7 +601,7 @@ //Draw Image Filters To Screen if (bGPUMode) filter->drawGPU(); else filter->draw(); - + ofSetColor(0x000000); if (bShowPressure) { @@ -614,6 +659,9 @@ verdana.drawString(buf, 740, 480); } + + if (hsvFilter && hsvFilter->isEnabled()) + hsvFilter->draw(); ofSetColor(0xFF0000); verdana.drawString("Press spacebar to toggle fast mode", 730, 572); @@ -811,14 +859,19 @@ *****************************************************************************/ void ofxNCoreVision::_mouseDragged(ofMouseEventArgs &e) { - if (showConfiguration) + if (showConfiguration) { + if (_handleColorSelection(e)) + return; controls->mouseDragged(e.x, e.y, e.button); //guilistener + } } void ofxNCoreVision::_mousePressed(ofMouseEventArgs &e) { if (showConfiguration) { + if (_handleColorSelection(e)) + return; controls->mousePressed(e.x, e.y, e.button); //guilistener if (e.x > 722 && e.y > 586){ofLaunchBrowser("http://tbeta.nuigroup.com");} } @@ -830,6 +883,45 @@ controls->mouseReleased(e.x, e.y, 0); //guilistener } +bool ofxNCoreVision::_handleColorSelection(ofMouseEventArgs &e) +{ + if (hsvFilter && hsvFilter->isEnabled()) { + static const ofRectangle srcImgBounds(40, 30, 320, 240); + if (e.x >= srcImgBounds.x && e.x <= srcImgBounds.x + srcImgBounds.width + && e.y >= srcImgBounds.y && e.y <= srcImgBounds.y + srcImgBounds.height) { + int imgX = e.x - srcImgBounds.x; + int imgY = e.y - srcImgBounds.y; + HSVColorFilter::Color color = hsvFilter->getColorAt(imgX, imgY); + //std::cout << " Hue " << color.h << std::endl; + if (color.h > 0) { + hsvFilter->setHue(0, color.h); + hsvFilter->setSaturationMin(0, max((int)(color.s * 0.7f),0)); + hsvFilter->setSaturationMax(0, min((int)(color.s * 1.3f),255)); + hsvFilter->setValueMin(0, max((int)(color.v * 0.7f),0)); + hsvFilter->setValueMax(0, min((int)(color.v * 1.3f),255)); + + bool yes = true; + controls->update(this->hsvFilter_use, kofxGui_Set_Bool, &yes, sizeof(bool)); + + float val = hsvFilter->getHue(); + controls->update(this->hsvFilter_hue, kofxGui_Set_Float, &val, sizeof(float)); + val = hsvFilter->getSaturationMin(); + controls->update(this->hsvFilter_satMin, kofxGui_Set_Float, &val, sizeof(float)); + val = hsvFilter->getSaturationMax(); + controls->update(this->hsvFilter_satMax, kofxGui_Set_Float, &val, sizeof(float)); + val = hsvFilter->getValueMin(); + controls->update(this->hsvFilter_valMin, kofxGui_Set_Float, &val, sizeof(float)); + val = hsvFilter->getValueMax(); + controls->update(this->hsvFilter_valMax, kofxGui_Set_Float, &val, sizeof(float)); + + filter->bLearnBakground = true; + return true; + } + } + } + return false; +} + /***************************************************************************** * Getters *****************************************************************************/ Index: addons/ofxNCore/src/Modules/ofxNCoreVision.h =================================================================== --- addons/ofxNCore/src/Modules/ofxNCoreVision.h (revision 176) +++ addons/ofxNCore/src/Modules/ofxNCoreVision.h (working copy) @@ -30,6 +30,13 @@ //Our Addon #include "ofxNCore.h" +#ifdef TARGET_WIN32 +// HSV filter +#include "Filters/HSVColorFilter.h" +#else +#include "HSVColorFilter.h" +#endif + //height and width of the source/tracked draw window #define MAIN_WINDOW_HEIGHT 240.0f #define MAIN_WINDOW_WIDTH 320.0f @@ -95,6 +102,14 @@ savePanel, kParameter_SaveXml, kParameter_File, + + hsvFilter_use, + hsvFilter_hue, + hsvFilter_hueRange, + hsvFilter_satMin, + hsvFilter_satMax, + hsvFilter_valMin, + hsvFilter_valMax }; public: @@ -154,6 +169,8 @@ #else bStandaloneMode = false; #endif + + hsvFilter = 0; } ~ofxNCoreVision() @@ -175,6 +192,8 @@ delete ffmv; } #endif + if (hsvFilter) + delete hsvFilter; } /**************************************************************** @@ -189,6 +208,7 @@ void _mousePressed(ofMouseEventArgs &e); void _mouseDragged(ofMouseEventArgs &e); void _mouseReleased(ofMouseEventArgs &e); + bool _handleColorSelection(ofMouseEventArgs &e); //Key Events void _keyPressed(ofKeyEventArgs &e); void _keyReleased(ofKeyEventArgs &e); @@ -324,6 +344,8 @@ char fileName [80]; FILE * stream ; + // HSV filter + HSVColorFilter *hsvFilter; }; #endif