Пример #1
0
int	main(int argc, char *argv[]) {
	int	c;
	int	width = 512;
	int	height = 512;
	while (EOF != (c = getopt(argc, argv, "x:y:a:w:h:")))
		switch (c) {
		case 'a':
			angle = atof(optarg);
			break;
		case 'x':
			translation.x = atof(optarg);
			break;
		case 'y':
			translation.y = atof(optarg);
			break;
		case 's':
			scale = atof(optarg);
			break;
		case 'w':
			width = atoi(optarg);
			break;
		case 'h':
			height = atoi(optarg);
			break;
		}

	if ((argc - optind) != 2) {
		std::cerr << "need exactly two filename arguments" << std::endl;
		exit(EXIT_FAILURE);
	}

	const char	*infile = argv[optind++];
	const char	*outfile = argv[optind];

	// read the infile
	cv::Mat	inimg = cv::imread(std::string(infile));
	cv::Size	size(inimg.cols, inimg.rows);
	cv::Point2d	center(size.width / 2, size.height / 2);

	cv::Rect	rect(center.x - width / 2, center.y - height / 2,
				width, height);

	// the the transform
	cv::Mat	rotmat = cv::getRotationMatrix2D(center, angle, 1);
	rotmat.at<double>(0, 2) += translation.x;
	rotmat.at<double>(1, 2) += translation.y;
	std::cout << rotmat << std::endl;

	// apply the transform
	cv::Mat	outimg(size.width, size.height, CV_32FC1);
	cv::warpAffine(inimg, outimg, rotmat, size);

	// write the outfile
	imwrite(std::string(outfile), outimg(rect));

	exit(EXIT_SUCCESS);
}
Пример #2
0
bool CFaceDetect::detectByAsm( const Mat &faceImage,vector<CFaceRect> &rclist,bool onlybig )
{
	int foundface = 0;
	float landmarks[2 * stasm_NLANDMARKS]; // x,y coords (note the 2)
	//if(!stasm_init("../model",0))
	//{
	//	return ;
	//}
	Mat_<unsigned char> matimage = faceImage;
	//detect face
	if (!stasm_open_image((const char*)matimage.data, faceImage.cols, faceImage.rows, "image",
				onlybig?0:1 /*multiface*/, 10 /*minwidth*/))
	{
		//cout<<"detect face failed !!"<<stasm_lasterr()<<endl;	
		return false;
	}
	Mat_<unsigned char> outimg(faceImage.clone());
	for(;;)
	{
		CFaceRect facerect;
		//find all the face
		if(!stasm_search_auto(&foundface, landmarks))
		{
			return false;
		}

		if(foundface == 0)
		{
			break;
		}

		facerect.noalign = false;
		//landmarks inner the image
		stasm_force_points_into_image(landmarks, faceImage.cols, faceImage.rows);
		getAsmPointer(landmarks,facerect.rcface);
		//printLandmarks(landmarks);
		//drawLandmarks(outimg, landmarks);
		//markLandmarks(outimg, landmarks);

		facerect.rcfullface = facerect.rcface;
		facerect.rclefteye = Rect((int)landmarks[L_LPupil * 2],(int)landmarks[L_LPupil * 2 + 1],1,1);
		facerect.rcrighteye = Rect((int)landmarks[L_RPupil * 2],(int)landmarks[L_RPupil * 2 + 1],1,1);
		facerect.rcmouth = Rect((int)landmarks[L_CTopOfTopLip * 2],(int)landmarks[L_CTopOfTopLip * 2 + 1],1,1);
		//cout<<"eye "<<facerect.rclefteye.x<<" "<<facerect.rclefteye.y<<" "<<facerect.rcrighteye.x<<" "<<facerect.rcrighteye.y<<" "<<facerect.rcmouth.x<<" "<<facerect.rcmouth.y<<endl;
		outimg(cvRound(landmarks[L_LPupil*2+1]),cvRound(landmarks[2*L_LPupil]))=255;
		outimg(cvRound(landmarks[L_RPupil*2+1]),cvRound(landmarks[2*L_RPupil]))=255;
		outimg(cvRound(landmarks[L_CTopOfTopLip*2+1]),cvRound(landmarks[2*L_CTopOfTopLip]))=255;
		rclist.push_back(facerect);
	}
	return true;
	//imwrite("test_stasm_lib_auto.bmp", outimg);

}
Пример #3
0
void interface::saveImageStart()
{
    bool ok;
    QString filename = QInputDialog::getText(this, tr("Save Image..."),
                                         QDir::currentPath().append("/"), QLineEdit::Normal,
                                              "wallpaper", &ok);
    if (ok && !filename.isEmpty())
    {
          double worldY, worldX, pixX;
          QImage outimg(settings::OWidth, settings::OHeight, QImage::Format_RGB32);

          for (unsigned int y = 0; y < settings::OHeight; y++)
              for (unsigned int x = 0; x <= ((settings::OWidth* 3)-1); x++)

              {   pixX=x/3;
                  worldY= settings::Height-y*settings::Height/settings::OHeight+settings::YCorner ;
                  worldX= pixX*settings::Width/settings::OWidth+settings::XCorner;

                  std::complex<double> fout=(*f)(worldX,worldY);        //run the point through our mathematical function
                  QRgb color = (*c)(fout);                              //...then turn that complex output into a color per our color wheel

                  outimg.setPixel(x/3, y, color);

        }

          filename+=".ppm";
          outimg.save(filename);
    }

}
Пример #4
0
int	main(int argc, char *argv[]) {
    int	c;
    int	l = 128;
    double	tx = 0, ty = 0;
    while (EOF != (c = getopt(argc, argv, "a:l:e:x:y:")))
        switch (c) {
        case 'e':
            epsilon = atof(optarg);
            break;
        case 'a':
            angle = atof(optarg);
            break;
        case 'l':
            l = atoi(optarg);
            break;
        case 'x':
            tx = atof(optarg);
            break;
        case 'y':
            ty = atof(optarg);
            break;
        }

    if ((argc - optind) != 3) {
        fprintf(stderr, "need exactly two arguments\n");
        exit(EXIT_FAILURE);
    }

    const char	*infile = argv[optind++];
    const char	*rotatedfile = argv[optind++];
    const char	*recoveredfile = argv[optind];
    printf("rotate %s by angle %f to %s\n", infile, angle, rotatedfile);

    cv::Mat	inimg = cv::imread(std::string(infile));
    int	width = inimg.cols;
    int	height = inimg.rows;
    cv::Mat	ingray(width, height, CV_32FC1);
    cv::cvtColor(inimg, ingray, CV_BGR2GRAY);

    cv::Point	center = cv::Point(width/2, height/2);
    cv::Mat	rotmat = cv::getRotationMatrix2D(center, angle, 1);
    rotmat.at<double>(0, 2) += tx;
    rotmat.at<double>(1, 2) += ty;
    std::cout << rotmat << std::endl;
    cv::Mat	outimg(width, height, CV_32FC1);

    cv::warpAffine(ingray, outimg, rotmat, cv::Size(width, height));
    imwrite(std::string(rotatedfile), outimg);

    cv::Mat	transform = iteratedTransform(ingray, outimg, l);
    std::cout << transform << std::endl;

    inimg = cv::imread(std::string(infile));
    cv::Mat	recoveredimg(width, height, CV_32FC3);
    cv::warpAffine(inimg, recoveredimg, transform, cv::Size(width, height));
    imwrite(std::string(recoveredfile), recoveredimg);

    exit(EXIT_SUCCESS);
}
Пример #5
0
// ./Imgs/*.jpg   ./Sal/ 
int main(int argc,char *argv[])
{
	CV_Assert(argc == 3);
	string imgW = argv[1], salDir = argv[2];
	string imgDir, imgExt;
	vecS namesNE;
	CmFile::MkDir(salDir);
	int imgNum = CmFile::GetNamesNE(imgW, namesNE, imgDir, imgExt);

	for (int i = 0; i < imgNum; i++){
		if (CmFile::FilesExist(salDir + namesNE[i] + "_FT.png"))
			continue;


		vector<UINT> img(0);// or UINT* imgBuffer;
		int width(0);
		int height(0);


		PictureHandler picHand;
		picHand.GetPictureBuffer(imgDir + namesNE[i] + imgExt, img, width, height );
		int sz = width*height;

		Saliency sal;
		vector<double> salmap(0);
		sal.GetSaliencyMap(img, width, height, salmap, true);

		vector<UINT> outimg(sz);
		for( int i = 0; i < sz; i++ ){
			int val = int(salmap[i] + 0.5);
			outimg[i] = val << 16 | val << 8 | val;
		}

		picHand.SavePicture(outimg, width, height, namesNE[i], salDir, 0, "_FT");// 0 is for BMP and 1 for JPEG)

		Mat sal1u = imread(salDir + namesNE[i] + "_FT.bmp", CV_LOAD_IMAGE_GRAYSCALE);
		imwrite(salDir + namesNE[i] + "_FT.png", sal1u);
		CmFile::RmFile(salDir + namesNE[i] + "_FT.bmp");
	}
}
Пример #6
0
bool CFaceDetect::detectByAsmMarks( const Mat &faceImage,vector<float *> &vlandmarks,bool onlybig )
{
	int foundface = 0;
	Mat_<unsigned char> matimage = faceImage;
	//detect face
	if (!stasm_open_image((const char*)matimage.data, faceImage.cols, faceImage.rows, "image",
				onlybig?0:1 /*multiface*/, 10 /*minwidth*/))
	{
		return false;
	}
	Mat_<unsigned char> outimg(faceImage.clone());
	for(;;)
	{
		CFaceRect facerect;
		float *landmarks = new float[2 * stasm_NLANDMARKS]; // x,y coords (note the 2)
		//find all the face
		if(!stasm_search_auto(&foundface, landmarks))
		{
			return false;
		}

		if(foundface == 0)
		{
			break;
		}

		facerect.noalign = false;
		//landmarks inner the image
		stasm_force_points_into_image(landmarks, faceImage.cols, faceImage.rows);
		//printLandmarks(landmarks);
		//drawLandmarks(outimg, landmarks);
		//markLandmarks(outimg, landmarks);
		//imshow("tmp", outimg);

		vlandmarks.push_back(landmarks);
	}
	return true;
}
Пример #7
0
int main(int argc, char **argv)
{
    try {
        // parse command line
        if (argc != 3)
            throw CError(usage, argv[0]);
        int argn = 1;
        char *dataFileName = argv[argn++];
	char *outstem = argv[argn++];

	int writeParams = 1;
	int writeTimings = 1;

	FILE *debugfile = createDebugFile(writeParams, outstem, verbose, argc, argv);

	// Load datafile 
	int width, height, nLabels;
	std::vector<int> gt, data, lrPairwise, udPairwise;
	MRF::CostVal *dataCostArray, *hCue, *vCue;

	if (verbose)
	    fprintf(stderr, "Loading datafile...\n");
	
	LoadDataFile(dataFileName, width, height, nLabels, dataCostArray, hCue, vCue);

	DataCost *dcost = new DataCost(dataCostArray);
	SmoothnessCost *scost = new SmoothnessCost(1, 1, 1, hCue, vCue);
	EnergyFunction *energy = new EnergyFunction(dcost, scost);

	if (verbose)
	    fprintf(stderr, "Running optimization...\n");
	fflush(stderr);

	int MRFalg = aRunAll;

	int outerIter, innerIter;
	MRF *mrf = NULL;
	for (int numAlg = aICM; numAlg <= aBPM; numAlg++) {
	    outerIter = MAXITER;
	    innerIter = 1;
	    if (MRFalg < aRunAll && numAlg != MRFalg) continue;

	    startAlgInitTimer();

	    switch (numAlg) {
	    case aICM:       mrf = new ICM(width, height, nLabels, energy); innerIter = 5; break;
	    case aExpansion: mrf = new Expansion(width, height, nLabels, energy); break;
	    case aSwap:      mrf = new Swap(width, height, nLabels, energy); break;
	    case aTRWS:      mrf = new TRWS(width, height, nLabels, energy); break;
	    case aBPS:       mrf = new BPS(width, height, nLabels, energy);  
		//innerIter = 5; 
		break;
	    case aBPM:       mrf = new MaxProdBP(width, height, nLabels, energy);
		//innerIter = 2; 
		break;
	    default: throw new CError("unknown algorithm number");
	    }
	    if (debugfile)
		fprintf(debugfile, "******* Running %s for up to %d x %d iterations\n",
			algs[numAlg], outerIter, innerIter);

	    mrf->initialize();
	    mrf->clearAnswer();

	    bool initializeToWTA = false;
	    if (initializeToWTA) {
		if (debugfile)
		    fprintf(debugfile, "performing WTA\n");
		CByteImage disp;
		WTA(dataCostArray, width, height, nLabels, disp);
		writeDisparities(disp, 255, "WTA.png", debugfile);
		setDisparities(disp, mrf);
	    } else {
		mrf->clearAnswer();
	    }

	    float initTime = getAlgInitTime();
	    
	    FILE *timefile = createTimeFile(writeTimings, outstem, algs[numAlg], debugfile);

	    runAlg(mrf, numAlg, debugfile, timefile, outerIter, innerIter, initTime);

	    // save resulting labels as image
	    CShape sh(width, height, 1);
	    CByteImage outimg(sh);
	    int n = 0;
	    for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
		    outimg.Pixel(x, y, 0) = 255* mrf->getLabel(n);
		    n++;
		}
	    }

	    char fname[500];
	    sprintf(fname, "%s-%s.png", outstem, algs[numAlg]);
	    WriteImageVerb(outimg, fname, 1);
	    delete mrf;
	}

	if (writeParams)
	    fclose(debugfile);

	delete energy;
	delete scost;
	delete dcost;
	delete [] dataCostArray;
	delete [] hCue;
	delete [] vCue;
    }
    catch (CError &err) {
        fprintf(stderr, err.message);
        fprintf(stderr, "\n");
        return -1;
    }
    catch (bad_alloc) {
	fprintf(stderr, "*** Error: not enough memory\n");
	exit(1);
    }

    return 0;
}
Пример #8
0
int main(int argc, const char** argv)
{
    if (argc != 5)
        Exit("Usage: test_stasm_lib MULTI MINWIDTH TRACE IMAGE");

    const int multi = argv[1][0] - '0';
    if (multi != 0 && multi != 1)
        Exit("Usage: test_stasm_lib MULTI MINWIDTH TRACE IMAGE, "
             "with MULTI 0 or 1, you have MULTI %s", argv[1]);

    int minwidth = -1;
    if (sscanf(argv[2], "%d", &minwidth) != 1 ||
        minwidth < 1 || minwidth > 100)
        {
        Exit("Usage: test_stasm_lib MULTI MINWIDTH TRACE IMAGE with "
             "MINWIDTH 1 to 100,  you have MINWIDTH %s", argv[2]);
        }

    const int trace = argv[3][0] - '0';
    if (trace < 0 || trace > 1)
        Exit("Usage: test_stasm_lib MULTI MINWIDTH TRACE IMAGE, with TRACE 0 or 1");

    if (!stasm_init("../data", trace))
        Exit("stasm_init failed: %s", stasm_lasterr());

    const char* path = argv[4]; // image name
    stasm_printf("Reading %s\n", path);
    const cv::Mat_<unsigned char> img(cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE));
    if (!img.data) // could not load image?
        Exit("Cannot load %s", path);

    cv::Mat_<unsigned char> outimg(img.clone());

    if (!stasm_open_image((const char*)img.data, img.cols, img.rows,
                          path, multi != 0, minwidth))
        Exit("stasm_open_image failed: %s", stasm_lasterr());

    // Test stasm_search_auto.
    // The min face size was set in the above stasm_open_image call.

    float landmarks[2 * stasm_NLANDMARKS]; // x,y coords
    int iface = 0;
    while (1)
        {
        stasm_printf("--- Auto Face %d ---\n", iface);
        int foundface;
        float estyaw;
        if (!stasm_search_auto_ext(&foundface, landmarks, &estyaw))
            Exit("stasm_search_auto failed: %s", stasm_lasterr());
        if (!foundface)
            {
            stasm_printf("No more faces\n");
            break; // note break
            }
        char s[100]; sprintf(s, "\nFinal with auto init (estyaw %.0f)", estyaw);
        PrintLandmarks(landmarks, s);
        DrawLandmarks(outimg, landmarks);
        iface++;
        if (trace)
            stasm_printf("\n");
        }
    imwrite("test_stasm_lib_auto.bmp", outimg);
    if (stasm_NLANDMARKS != 77)
    {
        stasm_printf(
            "Skipping pinned test because stasm_NLANDMARKS is %d not 77\n",
            stasm_NLANDMARKS);
    }
    else if (multi == 0 && minwidth == 25 && iface)
    {
        // Test stasm_search_pinned.  A human user is not at hand, so gyp by using
        // points from the last face found above for our 5 start points

        stasm_printf("--- Pinned Face %d ---\n", iface);
        float pinned[2 * stasm_NLANDMARKS]; // x,y coords
        memset(pinned, 0, sizeof(pinned));
        pinned[L_LEyeOuter*2]      = landmarks[L_LEyeOuter*2] + 2;
        pinned[L_LEyeOuter*2+1]    = landmarks[L_LEyeOuter*2+1];
        pinned[L_REyeOuter*2]      = landmarks[L_REyeOuter*2] - 2;
        pinned[L_REyeOuter*2+1]    = landmarks[L_REyeOuter*2+1];
        pinned[L_CNoseTip*2]       = landmarks[L_CNoseTip*2];
        pinned[L_CNoseTip*2+1]     = landmarks[L_CNoseTip*2+1];
        pinned[L_LMouthCorner*2]   = landmarks[L_LMouthCorner*2];
        pinned[L_LMouthCorner*2+1] = landmarks[L_LMouthCorner*2+1];
        pinned[L_RMouthCorner*2]   = landmarks[L_RMouthCorner*2];
        pinned[L_RMouthCorner*2+1] = landmarks[L_RMouthCorner*2+1];

        memset(landmarks, 0, sizeof(landmarks));
        if (!stasm_search_pinned(landmarks,
                pinned, (const char*)img.data, img.cols, img.rows, path))
            Exit("stasm_search_pinned failed: %s", stasm_lasterr());
        PrintLandmarks(landmarks, "Final with pinned init");
        outimg = img.clone();
        DrawLandmarks(outimg, landmarks);
        imwrite("test_stasm_lib_pinned.bmp", outimg);

        // test stasm_convert_shape
        float newlandmarks[2 * stasm_NLANDMARKS]; // x,y coords

        memcpy(newlandmarks, landmarks, 2 * stasm_NLANDMARKS * sizeof(float));
        stasm_convert_shape(newlandmarks, 68);
        PrintLandmarks(newlandmarks, "stasm77 to xm2vts");
#if 0
        outimg = img.clone();
        DrawLandmarks(outimg, newlandmarks, 68);
        imwrite("test_stasm_lib_68.bmp", outimg);
#endif
        memcpy(newlandmarks, landmarks, 2 * stasm_NLANDMARKS * sizeof(float));
        stasm_convert_shape(newlandmarks, 76);
        PrintLandmarks(newlandmarks, "stasm77 to stasm76");
#if 0
        outimg = img.clone();
        DrawLandmarks(outimg, newlandmarks, 76);
        imwrite("test_stasm_lib_76.bmp", outimg);
#endif

#if 0
        memcpy(newlandmarks, landmarks, 2 * stasm_NLANDMARKS * sizeof(float));
        stasm_convert_shape(newlandmarks, 22);
        PrintLandmarks(newlandmarks, "stasm77 to stasm22");
        outimg = img.clone();
        DrawLandmarks(outimg, newlandmarks, 22);
        imwrite("test_stasm_lib_22.bmp", outimg);

        memcpy(newlandmarks, landmarks, 2 * stasm_NLANDMARKS * sizeof(float));
        stasm_convert_shape(newlandmarks, 20);
        PrintLandmarks(newlandmarks, "stasm77 to stasm20");
        outimg = img.clone();
        DrawLandmarks(outimg, newlandmarks, 20);
        imwrite("test_stasm_lib_20.bmp", outimg);
#endif
    }

    return 0;       // success
}