예제 #1
0
void Detector::getHistogramNonSkin(){
    std::vector<std::string> listFile = getExamples(dirExamplesNonSkin);
    for (std::vector<std::string>::iterator it = listFile.begin() ; it != listFile.end(); ++it){
        char imageUrl[128];
        sprintf(imageUrl, "%s/%s", dirExamplesNonSkin, (*it).c_str());
        cv::Mat image = cv::imread(imageUrl, CV_LOAD_IMAGE_UNCHANGED);
        cv::cvtColor(image, image, CV_BGR2Lab);     

        for (int row = 0; row < image.size().height; row++){
            for (int col = 0; col < image.size().width; col++){
                cv::Vec3b labPixel = image.at<cv::Vec3b>(row, col);
                //calculer index
                if(labPixel.val[0] == 0 && labPixel.val[1] == 128 && labPixel.val[2] == 128){
                    continue;
                }
                int a = (int)labPixel.val[1]*scale / MAX_VALUE;
                int b = (int)labPixel.val[2]*scale / MAX_VALUE;
                histoNS[b][a] ++;
                totalPixelNonSkin++;
            }
        }
        totalPixelNonSkinBase += image.size().width * image.size().height;
        //        getHistogram(imageUrl, false); 
    }   
}  
예제 #2
0
void Detector::massDetect(){
    std::vector<std::string> listFile = getExamples(testDir); 

//    double possibilityOfSkin = 1.0*totalPixelSkin/totalPixelSkinBase;
//    double possibilityOfNonSkin = 1.0*totalPixelNonSkin/totalPixelNonSkinBase;
    double delta = (1.0*totalPixelSkin/totalPixelSkinBase)/(1.0*totalPixelNonSkin/totalPixelNonSkinBase);
    for (std::vector<std::string>::iterator it = listFile.begin() ; it != listFile.end(); ++it){
        char imageUrl[128];
        sprintf(imageUrl, "%s/%s", testDir, (*it).c_str());
        cv::Mat img2;    
        cv::Mat img = cv::imread(imageUrl, CV_LOAD_IMAGE_UNCHANGED);
        if(!img.data){
            printf("Detector, No data: %s\n", imageUrl );
        }
        cv::GaussianBlur(img, img, cv::Size(3,3), 0);
        cv::cvtColor(img, img, CV_BGR2Lab);
        img.copyTo(img2);

std::cout<<"---------------------------------------------------------"<<std::endl;
        for (int row = 0; row < img.size().height; row++){
            for (int col = 0; col < img.size().width; col++){
                cv::Vec3b labPixel = img.at<cv::Vec3b>(row, col);
                //calculer index
                int a = (int)labPixel.val[1]*scale / MAX_VALUE;
                int b = (int)labPixel.val[2]*scale / MAX_VALUE;
                double ps = 1.0*histoS[b][a]/totalPixelSkinBase; 
                double pns = 1.0*histoNS[b][a]/totalPixelNonSkinBase; 
//                std::cout<<a<< "  " << b << "  "<<histoS[b][a] << "  "<< histoNS[b][a] << "  "<< 1.0*histoS[b][a]/totalPixelSkinBase <<"  "<<  1.0*histoNS[b][a]/totalPixelNonSkinBase<< std::endl; 
                labPixel.val[1] = 128;
                labPixel.val[2] = 128;
                labPixel.val[0] = 0;
//                if(possibilityIsSkin < possibilityOfNonSkin){
//                if(possibilityIsSkin < THRESHOLD){

                if(ps* delta/ pns < threshold){
                    img.at<cv::Vec3b>(row, col) = labPixel;
                }else{
                    img2.at<cv::Vec3b>(row, col) = labPixel;
                }

            }
        }
        cv::medianBlur(img, img, 5);
        cv::medianBlur(img2, img2, 5);
        cv::cvtColor(img, img, CV_Lab2BGR);
        cv::cvtColor(img2, img2, CV_Lab2BGR);
        //write image

        char imageOutSkin[128];
        char imageOutNonSkin[128];
        sprintf(imageOutSkin, "output/skin/%s",  (*it).c_str());
        sprintf(imageOutNonSkin, "output/nonskin/%s",  (*it).c_str());
        cv::imwrite(imageOutSkin, img);
        cv::imwrite(imageOutNonSkin, img2);
    }
                                                                                                                                                               
} 
예제 #3
0
static void explainIdentifiers(char *db, struct sqlConnection *conn, char *idField)
/* Tell the user what field(s) they may paste/upload values for, and give
 * some examples. */
{
char *xrefTable = NULL, *xrefIdField = NULL, *aliasField = NULL;
getXrefInfo(conn, &xrefTable, &xrefIdField, &aliasField);
hPrintf("The items must be values of the <B>%s</B> field of the currently "
	"selected table, <B>%s</B>",
	idField, curTable);
if (aliasField != NULL)
    {
    if (sameString(curTable, xrefTable))
	{
	if (!sameString(idField, aliasField))
	    hPrintf(", or the <B>%s</B> field.\n", aliasField);
	else
	    hPrintf(".\n");
	}
    else
	hPrintf(", or the <B>%s</B> field of the alias table <B>%s</B>.\n",
		aliasField, xrefTable);
    }
else
    hPrintf(".\n");
hPrintf("(The \"describe table schema\" button shows more information about "
	"the table fields.)\n");

// on a browserbox, db is on the UCSC server, so cannot select into db, even if temporary
if (!isCustomTrack(curTable) && !hIsBrowserbox() && sqlCanCreateTemp(conn))
    {
    struct slName *exampleList = NULL, *ex;
    hPrintf("Some example values:<BR>\n");
    exampleList = getExamples(db, conn, curTable, idField,
			      aliasField != NULL ? 3 : 5);
    for (ex = exampleList;  ex != NULL;  ex = ex->next)
	{
	char *tmp = htmlEncode(ex->name);
	hPrintf("<TT>%s</TT><BR>\n", tmp);
	freeMem(tmp);
	}

    if (aliasField != NULL)
	{
	char tmpTable[512];
	char query[2048];
	// do not use any db. prefix on curTable for name
	char *plainCurTable = strrchr(curTable, '.');  
	if (plainCurTable)
	    plainCurTable++;
	else
	    plainCurTable = curTable;
	safef(tmpTable, sizeof(tmpTable), "hgTemp.tmp%s%s", plainCurTable, xrefTable);
	if (differentString(xrefTable, curTable))
	    sqlSafef(query, sizeof(query),
		  "create temporary table %s select %s.%s as %s from %s,%s "
		  "where %s.%s = %s.%s and %s.%s != %s.%s limit 100000",
		  tmpTable, xrefTable, aliasField, aliasField, xrefTable, curTable,
		  xrefTable, xrefIdField, curTable, idField,
		  xrefTable, xrefIdField, xrefTable, aliasField);
	else
	    sqlSafef(query, sizeof(query),
		  "create temporary table %s select %s from %s "
		  "where %s != %s limit 100000",
		  tmpTable, aliasField, xrefTable, aliasField, xrefIdField);
	sqlUpdate(conn, query);

	exampleList = getExamples(db, conn, tmpTable, aliasField, 3);
	for (ex = exampleList;  ex != NULL;  ex = ex->next)
	    hPrintf("<TT>%s</TT><BR>\n", ex->name);
	}
    hPrintf("\n");
    }
}