Example #1
0
static PyObject* Py_init(            
	PyObject*	self,
	PyObject*	args,
	PyObject*	kwargs)
{
	const char*	datadir	= PyStr_AS_STRING(datadir_default);
	int		trace	= 0;

	static const char* kwlist[] = {"datadir", "trace", NULL};

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si:init",
					const_cast<char**>(kwlist), &datadir,
					&trace))
		return NULL;

	if (trace != 0 && trace != 1)
	{
		PyErr_SetString(PyExc_TypeError, trace_error);
		return NULL;
	}

	if (!stasm_init(datadir, trace))
	{
		PyErr_SetString(StasmException, stasm_lasterr());
		return NULL;
	}

	Py_RETURN_NONE;
}
Example #2
0
QStasm::QStasm(QObject *parent, uchar length) :
    QObject(parent)
{
    #ifdef CASCADECLASSIFIERS_PATH
        stasm_init( QString(CASCADECLASSIFIERS_PATH).toUtf8().data() , 0);
    #else
        std::string dataPath = QCoreApplication::applicationDirPath().toStdString() + std::string("/data/");
        stasm_init( dataPath.data() , 0);
    #endif
    compositeFlag = false;
    m_pos = 0;
    m_historyLength = length;
    f_firstFrame = true;
    pt_points = new float*[2 * stasm_NLANDMARKS];
    for(int i = 0; i < 2 * stasm_NLANDMARKS; i++)
        pt_points[i] = new float[length];
}
Example #3
0
int main()
{
    if (!stasm_init("../data", 0 /*trace*/))
        error("stasm_init failed: ", stasm_lasterr());

    static const char* path = "../data/testface.jpg";

    cv::Mat_<unsigned char> img(cv::imread(path, CV_LOAD_IMAGE_GRAYSCALE));

    if (!img.data)
        error("Cannot load", path);

    if (!stasm_open_image((const char*)img.data, img.cols, img.rows, path,
                          1 /*multiface*/, 10 /*minwidth*/))
        error("stasm_open_image failed: ", stasm_lasterr());

    int foundface;
    float landmarks[2 * stasm_NLANDMARKS]; // x,y coords (note the 2)

    int nfaces = 0;
    while (1)
    {
        if (!stasm_search_auto(&foundface, landmarks))
             error("stasm_search_auto failed: ", stasm_lasterr());

        if (!foundface)
            break;      // note break

        // for demonstration, convert from Stasm 77 points to XM2VTS 68 points
        stasm_convert_shape(landmarks, 68);

        // draw the landmarks on the image as white dots
        stasm_force_points_into_image(landmarks, img.cols, img.rows);
        for (int i = 0; i < stasm_NLANDMARKS; i++)
            img(cvRound(landmarks[i*2+1]), cvRound(landmarks[i*2])) = 255;

        nfaces++;
    }
    printf("%s: %d face(s)\n", path, nfaces);
    fflush(stdout);
    cv::imwrite("minimal2.bmp", img);
    cv::imshow("stasm minimal2", img);
    cv::waitKey();

    return 0;
}
Example #4
0
static void main1(int argc, const char** argv)
{
    OpenLogFile();
    print_g = true; // want to be able to see lprintfs
    const bool old_trace = trace_g;
    if (!stasm_init("../data", 1 /*trace*/))
        Err("stasm_init failed %s", stasm_lasterr());
    trace_g = old_trace;

    ShapeFile sh;  // contents of the shape file
    FILE* fitfile; // the fit file we will create

    Init(sh, fitfile, argc, argv);

    const clock_t start_time = clock();
    ProcessShapes(sh, fitfile);
    lprintf("[MeanTimePerImg %.3f]\n",
        double(clock() - start_time) / (sh.nshapes_ * CLOCKS_PER_SEC));
    fclose(fitfile);
}
Example #5
0
static void main1(int argc, const char** argv)
{
    GetOptions(argc, argv);
    OpenLogFile();

    // argc is now the number of images and argv is the image filenames

    const bool old_trace = trace_g;
    if (!stasm_init("../data", 1 /*trace*/))
        Err("stasm_init failed %s", stasm_lasterr());
    trace_g = old_trace;

    const int ndigits = int(floor(log10(double(argc)) + 1)); // for aligning

    for (int i_img = 0; i_img < argc; i_img++)
    {
        const char* const imgpath = argv[i_img];
        if (argc > 1)
            lprintf("%*d ", ndigits, i_img);
        lprintf("%s: ", imgpath);
        ProcessImg(imgpath);
    }
}
bool CFaceDetect::Init(const char*path , int trace)
{

	return stasm_init(path, trace);

}
Example #7
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
}
FaceAlignment::FaceAlignment(std::string dataPath, QMutex& mutex) {
    commonTool.log(QString("Init Face Alignment with data path --> %1").arg(QString::fromStdString(dataPath)));
    this->dataPath = dataPath + "completeAR/";
    this->mutex = &mutex;
    stasm_init(this->dataPath.c_str(), 0);
}