Пример #1
0
int ImgDataTEST::T_setImg() {
	int fail = 0;
    logger->trace("==============================");

    logger->trace("Testing setImg():");
    logger->trace(" Creating 2 Mat obj using camCap()...");
    cv::Mat test = camCap();
    cvDestroyWindow("camCap");
    cv::Mat test2 = camCap();
    cvDestroyWindow("camCap");
    cv::namedWindow("obj 1");
    cv::imshow("obj 1",test);
    cv::namedWindow("obj 2");
    cv::imshow("obj 2",test2);
    logger->trace("  Accessing refcount...");
    int t1rc,t2rc,imgrc;
    t1rc = test.u->refcount;
    t2rc = test2.u->refcount;
    logger->trace("    Obj 1 refcount: "+StringTools::intToStr(t1rc));
    logger->trace("    Obj 2 refcount: "+StringTools::intToStr(t2rc));
    if (t1rc+t2rc==2)
        logger->trace("    ok");
    else {
        logger->warn("    NOT ok, refcount should be 1 for both");
    	fail++;
    }
    logger->trace(" Creating ImgData with obj 1...");
    ImgData* testImg = new ImgData("plswork", test);
    logger->trace("  Accessing refcount...");
    t1rc = test.u->refcount;
    t2rc = test2.u->refcount;
    imgrc = testImg->img.u->refcount;
    logger->trace("    Obj 1 refcount: "+StringTools::intToStr(t1rc));
    logger->trace("    Obj 2 refcount: "+StringTools::intToStr(t2rc));
    if (t1rc == 2) {
    	if (imgrc == 2) {
    		if(t2rc == 1)
                logger->trace("    ok");
    		else {
                logger->warn("    NOT ok, obj 2 refcount should be 1");
    			fail++;
    		}
    	}
    	else {
            logger->warn("    NOT ok, obj 1 refcount disagree");
    		fail++;
    	}
    } else {
        logger->warn("    NOT ok, obj 1 refcount should be 2");
    	fail++;
    }
    logger->trace(" Try showImg(), expect photo to be as same as obj 1...");
    logger->trace(" If true, hit space, else hit esc...");
    testImg->showImg();
    char key;
    while (1) {
    	key = cvWaitKey(0);
    	if (char(key) == 32) {
            logger->trace("    ok");
    		break;
    	}
    	else if (char(key) == 27) {
            logger->warn("    NOT ok, img not expected");
    		fail++;
    		break;
    	}
    }
    logger->trace(" Setting obj 2 to img...");
    testImg->setImg(test2);
    logger->trace("  Accessing refcount...");
    t1rc = test.u->refcount;
    t2rc = test2.u->refcount;
    logger->trace("    Obj 1 refcount: "+StringTools::intToStr(t1rc));
    logger->trace("    Obj 2 refcount: "+StringTools::intToStr(t2rc));
    if (t1rc==1 && t2rc==2)
        logger->trace("    ok");
    else {
        logger->warn("    NOT ok, refcount should be 1 for obj 1 and 2 for obj 2");
    	fail++;
    }
    logger->trace(" Release obj 2 from outside ImgData...");
    test2.release();
    logger->trace(" Try showImg(), expect photo to be as same as obj 2...");
    testImg->showImg();
    logger->trace(" If true, hit space, else hit esc...");
    while (1) {
    	key = cvWaitKey(0);
    	if (char(key) == 32) {
            logger->trace("    ok");
    		break;
    	}
    	else if (char(key) == 27) {
            logger->warn("    NOT ok, img not expected");
    		fail++;
    		break;
    	}
    }
    logger->trace("  Accessing refcount...");
    t1rc = test.u->refcount;
    imgrc = testImg->img.u->refcount;
    logger->trace("    Obj 1 refcount: "+StringTools::intToStr(t1rc));
    logger->trace("    Obj 2 refcount: "+StringTools::intToStr(imgrc));
    if (t1rc+imgrc==2)
        logger->trace("    ok");
    else {
        logger->warn("    NOT ok, refcount should be 1 for both");
    	fail++;
    }
    logger->trace(" Deleting ImgData...");
    delete testImg;
    logger->trace(" Release obj 1...");
    test.release();
    cv::destroyWindow("obj 1");
    cv::destroyWindow("obj 2");

	if (fail > 0)
        logger->warn("  TEST FAILED: setImg()");
    logger->trace("==============================");
	return fail;
}
Пример #2
0
bool RGBFilter::filter(Data* data) {
	// check for whether the input is of the correct type.
	ImgData* cast = dynamic_cast<ImgData*>(data);
	if (cast == 0) {
		// track the error and return error
		this->track(data,this->filterID,1,1);
        return false;
	}

    if (cast->img.type() != 16) {
		this->track(data,this->filterID,2,1);
        return false;
	}

	// begin filter sequence.
	int newPixelVal;
    cv::Mat src = cast->getImg();
    cv::Mat filteredImg = src.clone();
	cv::Mat BGR[3];

	cv::split(filteredImg,BGR);
	// catch error?

	// Full spectrum mode
	if(this->mode == 0) {
        for(int y = 0; y < src.cols; y++ ) {
            for(int x = 0; x < src.rows; x++ ) {
				for(int c = 0; c < 3; c++) {
                    newPixelVal = std::max(0,std::min(mxColour,BGR[c].at<unsigned char>(x,y) + midMult[c]*midtone[c]));
					BGR[c].at<unsigned char>(x,y) = newPixelVal;
				}
			}
		}
	}

	// 3 zone mode
	if (this->mode == 1) {
		int luminosity;
        const int SHADTHRESHOLD = (int) mxColour*10/3;
		const int HIGHTHRESHOLD = SHADTHRESHOLD * 2;
		// get luminosity with some function
		// use luminosity as a switch for case using high, mid or shad
        for(int y = 0; y < src.cols; y++ ) {
            for(int x = 0; x < src.rows; x++ ) {
				// From 11%,59%,30% bgr respectively. Scaled to 1:6:3 factors
				// luminosity range is from 0-2550, 1/3 is 850. Calc this from:
				// 10*255, 10* MXCOLOR
				luminosity = BGR[0].at<unsigned char>(x,y)*1+BGR[1].at<unsigned char>(x,y)*6+BGR[2].at<unsigned char>(x,y)*3;

				for(int c = 0; c < 3; c++) {

					if (luminosity < SHADTHRESHOLD)
                        newPixelVal = std::max(0,std::min(mxColour,BGR[c].at<unsigned char>(x,y) + shadMult[c]*shadow[c]));
					else if (luminosity > HIGHTHRESHOLD)
                        newPixelVal = std::max(0,std::min(mxColour,BGR[c].at<unsigned char>(x,y) + highMult[c]*highlight[c]));
					else
                        newPixelVal = std::max(0,std::min(mxColour,BGR[c].at<unsigned char>(x,y) + midMult[c]*midtone[c]));

					BGR[c].at<unsigned char>(x,y) = newPixelVal;
				}
			}
		}
	}

	//joining seq
	cv::merge(BGR,3,filteredImg);

	//set sequence
    cast->setImg(filteredImg);

	// end sequence.

	// track and return
	this->track(cast,this->filterID,0,0);
    return true;
}