Color Tracking and Background Subtraction

#1

Hi all, I am trying to do color tracking and background subtraction to track IR light with a modded webcam. I’m currently using ofxCv and i am having trouble integrating both color tracking and background subtraction. Im getting the following error: “OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cvtColor”

Here’s the code:

void ofApp::setup(){
cam.setup(640,360);

learningTime = 500;

thresh.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_GRAYSCALE);

contourFinder.setTargetColor(targetColor, TRACK_COLOR_HSV);
contourFinder.setMinAreaRadius(10);
contourFinder.setMaxAreaRadius(150);

}

void ofApp::update(){
cam.update();

if(resetBackground) {
    background.reset();
    resetBackground = false;
}


if(cam.isFrameNew()){
    contourFinder.setTargetColor(targetColor, TRACK_COLOR_HSV);
    targetColor.setHsb(208, 100, 100);
    contourFinder.setThreshold(threshold);

    background.setLearningTime(learningTime);
    background.setThresholdValue(150);
    background.update(cam, thresh);

    contourFinder.findContours(thresh);

    thresh.update();
}

}