Esempio n. 1
0
int camDrawRectangle(CamImage *image, int x1, int y1, int x2, int y2, int color)
{
    camDrawLine(image,x1,y1,x2,y1,color);
    camDrawLine(image,x2,y1,x2,y2,color);
    camDrawLine(image,x2,y2,x1,y2,color);
    camDrawLine(image,x1,y2,x1,y1,color);
    return 1;
}
Esempio n. 2
0
int camPlot(CamImage *image, int x, int y, int color, int kind)
{
    if (kind&1) {
        camDrawLine(image,x,y,x,y,color);
    }
    if (kind&2) {
	camDrawLine(image,x-2,y-2,x+2,y+2,color);
        camDrawLine(image,x+2,y-2,x-2,y+2,color);
    }
    if (kind&4) {
	camDrawCircle(image,x,y,2,color);
    }
    return 1;
}
Esempio n. 3
0
int main()
{
    CamImage imodel[3], image, color_image;
    CamKeypoints points[3], points2;
    int i, j;
    CamKeypointsMatches matches;
    char filename[256];
    char *model_images[] = {"edog5", "dvd", "mrpotato4"};
#define DISPLAYED_MODEL 2
#define NB_SCENES 5
    char *test_images[NB_SCENES] = {"scene1", "scene3", "scene4", "scene5", "scene7"};

    const int cx[3] = {450, 390, 550};
    const int cy[3] = {340, 510, 450};
    const int width[3] = {720, 690, 500};
    const int height[3] = {640, 910, 500};
    CamAffineTransform t;
    int error, c, x1, y1, x2, y2, score, nbFeatures;
    CamPoint xy[7], uv[7];
    CamImage dimage;
    CamROI roi;

    const int nb_keypoints = 500;

    for (i = 0; i < 3; i++) {
        sprintf(filename, "resources/photos/%s.bmp", model_images[i]);
        printf("Feature point detection on %s ...\n", model_images[i]);
        imodel[i].imageData = NULL;
        camLoadBMP(&imodel[i], filename);
        /*
        camAllocateImage(&image, imodel[i].width, imodel[i].height, CAM_DEPTH_8U);
        camRGB2Y(&imodel[i], &image);
        */
        camAllocateYUVImage(&image, imodel[i].width, imodel[i].height);
        camRGB2YUV(&imodel[i], &image);
        camAllocateKeypoints(&points[i], 0);
        points[i].id = i;
        camFastHessianDetector(&image, &points[i], 100, CAM_UPRIGHT);
        /*
        camDrawKeypoints(&points[i], &image, 128);
        sprintf(filename, "output/%s.pgm", model_images[i]);
        camSavePGM(&image, filename);
        	*/
        camDeallocateImage(&image);
    }

    camAllocateRGBImage(&dimage, imodel[0].width, imodel[0].height * 2);
    camSetROI(&roi, 0, 0, imodel[0].height, imodel[0].width, imodel[0].height);

    camAllocateKeypointsMatches(&matches, 2048);
    nbFeatures = 0;
    score = 0;

    for (i = 0; i < NB_SCENES; i++) {
        sprintf(filename, "resources/photos/%s.bmp", test_images[i]);
        printf("Feature point detection on %s ...\n", test_images[i]);
        color_image.imageData = NULL;
        camLoadBMP(&color_image, filename);
        /*
        camAllocateImage(&image, color_image.width, color_image.height, CAM_DEPTH_8U);
        camRGB2Y(&color_image, &image);
        */
        camAllocateYUVImage(&image, color_image.width, color_image.height);
        camRGB2YUV(&color_image, &image);
        camAllocateKeypoints(&points2, 0);
        camFastHessianDetector(&image, &points2, nb_keypoints, CAM_UPRIGHT);
        printf("# features = %d\n", points2.nbPoints);
        nbFeatures += points2.nbPoints;

        // Create result image
        dimage.roi = NULL;
        camCopy(&imodel[DISPLAYED_MODEL], &dimage);
        dimage.roi = &roi;
        camCopy(&color_image, &dimage);
        dimage.roi = NULL;
        camDrawKeypoints(&points[DISPLAYED_MODEL], &dimage, 128);

        for (j = 0; j < 3; j++) {
            camKeypointsMatching2(&points[j], &points2, &matches);
            // Find affine parameters
            if (camFindAffineTransform2(&matches, &t, &error)) {
                score += matches.nbMatches - matches.nbOutliers;
                if (j == DISPLAYED_MODEL) {
                    // Draw lines between model and target
                    for (c = 0; c < matches.nbMatches; c++) {
                        if (matches.pairs[c].mark != -1) {
                            camDrawKeypoint(matches.pairs[c].p1, &dimage, CAM_RGB(255, 0, 0));
                            x1 = matches.pairs[c].p1->x;
                            y1 = matches.pairs[c].p1->y;
                            x2 = matches.pairs[c].p2->x;
                            y2 = matches.pairs[c].p2->y;
                            y2 += image.height;
                            camDrawLine(&dimage, x1, y1, x2, y2, CAM_RGB(0, 255, 0));
                        }
                    }
                    for (c = 0; c < matches.nbMatches; c++) {
                        matches.pairs[c].p2->y += image.height;
                        camDrawKeypoint(matches.pairs[c].p2, &dimage, 128);
                    }
                }

                // Draw box on model and target
                xy[0].x = xy[3].x = cx[j] - width[j] / 2;
                xy[0].y = xy[1].y = cy[j] - height[j] / 2;
                xy[1].x = xy[2].x = cx[j] + width[j] / 2;
                xy[2].y = xy[3].y = cy[j] + height[j] / 2;
                xy[4].x = xy[5].x = cx[j];
                xy[4].y = xy[6].y = cy[j];
                xy[5].y = cy[j] - height[j] / 4;
                xy[6].x = cx[j] + width[j] / 4;
                for (c = 0; c < 7; c++) {
                    camApplyAffineTransform(&xy[c], &uv[c], &t);
                    uv[c].y += image.height;
                }
                if (j == DISPLAYED_MODEL) {
                    camDrawLine(&dimage, xy[0].x, xy[0].y, xy[1].x, xy[1].y, 0);
                    camDrawLine(&dimage, xy[2].x, xy[2].y, xy[1].x, xy[1].y, 0);
                    camDrawLine(&dimage, xy[2].x, xy[2].y, xy[3].x, xy[3].y, 0);
                    camDrawLine(&dimage, xy[0].x, xy[0].y, xy[3].x, xy[3].y, 0);
                    camDrawLine(&dimage, xy[4].x, xy[4].y, xy[5].x, xy[5].y, 0);
                    camDrawLine(&dimage, xy[6].x, xy[6].y, xy[4].x, xy[4].y, 0);
                }
                camDrawLine(&dimage, uv[0].x, uv[0].y, uv[1].x, uv[1].y, 0);
                camDrawLine(&dimage, uv[2].x, uv[2].y, uv[1].x, uv[1].y, 0);
                camDrawLine(&dimage, uv[2].x, uv[2].y, uv[3].x, uv[3].y, 0);
                camDrawLine(&dimage, uv[0].x, uv[0].y, uv[3].x, uv[3].y, 0);
                camDrawLine(&dimage, uv[4].x, uv[4].y, uv[5].x, uv[5].y, 0);
                camDrawLine(&dimage, uv[6].x, uv[6].y, uv[4].x, uv[4].y, 0);
            }
        }

        sprintf(filename, "output/%s.bmp", test_images[i]);
        camSaveBMP(&dimage, filename);

        camDeallocateImage(&image);
        camDeallocateImage(&color_image);
        camFreeKeypoints(&points2);
    }

    for (i = 0; i < 3; i++) {
        camDeallocateImage(&imodel[i]);
        camFreeKeypoints(&points[i]);
    }
    camDeallocateImage(&dimage);
    camFreeKeypointsMatches(&matches);

    printf("# features in scenes = %d\n", nbFeatures);
    printf("# matching features = %d (%lg%%)\n", score, score*100.0/nbFeatures);

}
Esempio n. 4
0
int camDrawText16s(CamImage *image, char *text, int x, int y, int cwidth, int cheight, int orientation, int color)
{
    static const int characters_table[][16]={
        {1,1,1,1,1,1,1,1,0,0,1,0,0,0,1,0}, /* 0 */
        {1,0,0,0,1,1,0,0,0,1,0,0,0,1,0,0}, /* {0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0}, */
        {1,1,1,0,1,1,1,0,0,0,0,1,0,0,0,1},
        {1,1,1,1,1,1,0,0,0,0,0,1,0,0,0,0},
        {0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1},
        {1,1,0,1,1,1,0,1,0,0,0,1,0,0,0,1},
        {1,1,0,1,1,1,1,1,0,0,0,1,0,0,0,1},
        {1,1,0,0,0,0,0,0,0,0,1,0,0,0,1,0},
        {1,1,1,1,1,1,1,1,0,0,0,1,0,0,0,1},
        {1,1,1,1,1,1,0,1,0,0,0,1,0,0,0,1}, /* 9 */
        {1,1,1,1,0,0,1,1,0,0,0,1,0,0,0,1}, /* A */
        {1,1,1,1,1,1,0,0,0,1,0,1,0,1,0,0},
        {1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0},
        {1,1,1,1,1,1,0,0,0,1,0,0,0,1,0,0},
        {1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,1},
        {1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,1},
        {1,1,0,1,1,1,1,1,0,0,0,1,0,0,0,0},
        {0,0,1,1,0,0,1,1,0,0,0,1,0,0,0,1},
        {0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0},
        {0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,1,1,0,0,1,0,1,0,0,1},
        {0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},
        {0,0,1,1,0,0,1,1,1,0,1,0,0,0,0,0},
        {0,0,1,1,0,0,1,1,1,0,0,0,1,0,0,0},
        {1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0},
        {1,1,1,0,0,0,1,1,0,0,0,1,0,0,0,1},
        {1,1,1,1,1,1,1,1,0,0,0,0,1,0,0,0},
        {1,1,1,0,0,0,1,1,0,0,0,1,1,0,0,1},
        {1,1,0,1,1,1,0,1,0,0,0,1,0,0,0,1},
        {1,1,0,0,0,0,0,0,0,1,0,0,0,1,0,0},
        {0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,1,1,0,0,1,0,0,0,1,0},
        {0,0,1,1,0,0,1,1,0,0,0,0,1,0,1,0},
        {0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0},
        {0,0,0,0,0,0,0,0,1,0,1,0,0,1,0,0},
        {1,1,0,0,1,1,0,0,0,0,1,0,0,0,1,0}, /* Z */
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
        
    static const int segments[16][4]={
        {0,0,1,0},{1,0,2,0},{2,0,2,1},{2,1,2,2},
        {1,2,2,2},{0,2,1,2},{0,1,0,2},{0,0,0,1},
        {0,0,1,1},{1,0,1,1},{2,0,1,1},{2,1,1,1},
        {2,2,1,1},{1,2,1,1},{0,2,1,1},{0,1,1,1}
    };
        
    int i,j,l;
    int xp[3],yp[3];
    const int *character;
    int special_character;
    char carac;
    
    CAM_CHECK_ARGS(camDrawText16s,image->imageData!=NULL);
    
    if (orientation) {
        xp[0]=0; xp[1]=2*cwidth/5; xp[2]=4*cwidth/5;
        yp[0]=cheight; yp[1]=cheight-cheight/3; yp[2]=cheight-2*cheight/3;
    } else {
        xp[0]=0; xp[1]=cwidth/3; xp[2]=2*cwidth/3;
        yp[0]=0; yp[1]=2*cheight/5; yp[2]=4*cheight/5;
    }
    
    l=strlen(text);
    
    for (i=0;i<l;i++) {
        if (orientation) {
            carac=text[l-1-i];
        } else {
            carac=text[i];
        }
        special_character=0;
        if ((carac>='0')&&(carac<='9')) {
            character=characters_table[carac-'0'];
        } else if ((carac>='A')&&(carac<='Z')) {
            character=characters_table[carac-'A'+10];
        } else if ((carac>='a')&&(carac<='z')) {
            character=characters_table[carac-'a'+10];
        } else if (carac==' ') {
            /* Space character */
            special_character=1;
        } else if (carac==':') {
            special_character=1;
            if (orientation) {
                camDrawLine(image,x+xp[1],y+yp[1],x+xp[1],y+yp[1],color);
                camDrawLine(image,x+xp[2],y+yp[1],x+xp[2],y+yp[1],color);
            } else {
                camDrawLine(image,x+xp[1],y+yp[1],x+xp[1],y+yp[1],color);
                camDrawLine(image,x+xp[1],y+yp[2],x+xp[1],y+yp[2],color);
            }
        } else if (carac=='.') {
            special_character=1;
            if (orientation) {
                camDrawLine(image,x+xp[2],y+yp[1],x+xp[2],y+yp[1],color);
            } else {
                camDrawLine(image,x+xp[1],y+yp[2],x+xp[1],y+yp[2],color);
            }
        } else if (carac=='=') {
            special_character=1;
            if (orientation) {
                camDrawLine(image,x+xp[1],y+yp[0],x+xp[1],y+yp[2],color);
                camDrawLine(image,x+xp[2],y+yp[0],x+xp[2],y+yp[2],color);
            } else {
                camDrawLine(image,x+xp[0],y+yp[1],x+xp[2],y+yp[1],color);
                camDrawLine(image,x+xp[0],y+yp[2],x+xp[2],y+yp[2],color);
            }
        } else if (carac=='-') {
            special_character=1;
            if (orientation) {
                camDrawLine(image,x+xp[1],y+yp[0],x+xp[1],y+yp[2],color);
            } else {
                camDrawLine(image,x+xp[0],y+yp[1],x+xp[2],y+yp[1],color);
            }
        }
        
        if (!special_character) {
            if (orientation) {
                for (j=0;j<16;j++) {
                    if (character[j]) {
                        camDrawLine(image,x+xp[segments[j][1]],y+yp[segments[j][0]],x+xp[segments[j][3]],y+yp[segments[j][2]],color);
                    }
                }
            } else {
                for (j=0;j<16;j++) {
                    if (character[j]) {
                        camDrawLine(image,x+xp[segments[j][0]],y+yp[segments[j][1]],x+xp[segments[j][2]],y+yp[segments[j][3]],color);
                    }
                }
            }
        }
        if (orientation) {
            y+=cheight;
        } else {
            x+=cwidth;
        }
    }
    return 1;
}
Esempio n. 5
0
void test_camRecursiveKeypoints()
{
	CamImage image, dest;
	CamKeypoints points;
	int i;
	const int x = 8;
	int angle;
	double costheta;
	double sintheta;

	const int xp[4] = {-1, 1, 1, -1};
	const int yp[4] = {-1, -1, 1, 1};
	CamWarpingParams params;

	printf("Recursive keypoints detection :\n");
	camAllocateImage(&image, 256, 256, CAM_DEPTH_8U);
	camAllocateKeypoints(&points, 100);

	camSet(&image, 0);
	//     camDrawRectangle(&image, 102, 120, 156, 152, 128);
	//     camFillColor(&image, 103, 121, 128, -1);
	camDrawRectangle(&image, 120, 50, 150, 70, 28);
	camDrawRectangle(&image, 100, 35, 180, 90, 180);
	//     camFillColor(&image, 123, 36, 128, -1);
	//
	//     camDrawCircle(&image, 50, 50, 10, 128);
	//     camFillColor(&image, 50, 50, 128, -1);
	//     camDrawCircle(&image, 80, 50, 5, 128);
	//     camFillColor(&image, 80, 50, 128, -1);
	//     camDrawCircle(&image, 100, 50, 3, 128);
	//     camFillColor(&image, 100, 50, 128, -1);
	#if 1
	angle = 20;
	costheta = cos(angle * 2 * M_PI / 360);
	sintheta = sin(angle * 2 * M_PI / 360);
	for (i = 0; i < 4; i++) {
		params.p[i].x = (int)floor((costheta * xp[i] - sintheta * yp[i]) * 15 + 0.5);
		params.p[i].y = (int)floor((sintheta * xp[i] + costheta * yp[i]) * 15 + 0.5);
		params.p[i].x += 192;
		params.p[i].y += 192;
	}
	for (i = 0; i < 4; i++) {
		camDrawLine(&image, params.p[i].x, params.p[i].y, params.p[(i+1)%4].x, params.p[(i+1)%4].y, 128);
	}
	camFillColor(&image, 192, 192, 128, -1);

	angle = 30;
	costheta = cos(angle * 2 * M_PI / 360);
	sintheta = sin(angle * 2 * M_PI / 360);
	for (i = 0; i < 4; i++) {
		params.p[i].x = (int)floor((costheta * xp[i] - sintheta * yp[i]) * 10 + 0.5);
		params.p[i].y = (int)floor((sintheta * xp[i] + costheta * yp[i]) * 10 + 0.5);
		params.p[i].x += 50;
		params.p[i].y += 192;
	}

	for (i = 0; i < 4; i++) {
		camDrawLine(&image, params.p[i].x, params.p[i].y, params.p[(i+1)%4].x, params.p[(i+1)%4].y, 128);
	}
	camFillColor(&image, 50, 192, 128, -1);

	#endif
	dest.imageData = NULL;

	camKeypointsRecursiveDetector(&image, NULL, &points, 20, 0);
	for (i = 0; i < points.nbPoints; i++) {
		printf("x=%d y=%d value=%d scale=%d size=%d angle=%d\n", points.keypoint[i]->x, points.keypoint[i]->y, points.keypoint[i]->value, points.keypoint[i]->scale, points.keypoint[i]->size, points.keypoint[i]->angle);
	}
	camDrawKeypoints(&points, &image, 192);
	camSavePGM(&image, "output/keypoints_recursive.pgm");

	camDeallocateImage(&image);
	camDeallocateImage(&dest);
	camFreeKeypoints(&points);
}