예제 #1
0
void preProcess(IplImage *prv,IplImage *cur,IplImage *nxt,IplImage *wrt)
{    

	// 
	//cvSub(cur,prv,pImagePool[0]);
	//Detect(pImagePool[0],wrt,Robert);
	switch ( whichKernel)
	{
	case 0:
		// diff two img
		cvSub(cur,prv,wrt);
		break;
	case 1:
		Detect(wrt, cur,Robert);
		break;
	case 2:
		Detect(wrt, cur,Prewitt);
		break;
	case 3:
		Detect(wrt, cur,LapLas);
		break;
	case 4:
		histogramNormalize(wrt, cur);
		break;
	case 5:
		histogramNormalize(pImagePool[0], cur);
		Detect(wrt,pImagePool[0],Prewitt);
		break;
	case 6:
		{
			imgDFT(wrt, cur);
		}
		break;
	case 7:
		{
			Detect(wrt, cur,FreiChen);
			break;
		}
	case 8:
		{
			Filter(wrt, cur);
			break;
		}
	case 9:
		{

			transRGB2Gray( pImagePool[0], cur);
			Filter(wrt, pImagePool[0],averageFilter);

		}
	default:
		break;
	}

}
예제 #2
0
void preProcess(IplImage *prv,IplImage *cur,IplImage *nxt,IplImage *wrt)
{    

	switch ( whichKernel)
	{
	case 0:{
		// diff two img
		//eabcdm();
		//f();
		cvSub(cur,prv,wrt);
		//_asm{
		//	push 0;
		//	mov eax, wrt;
		//	push eax;
		//	mov eax, prv;
		//	push eax;
		//	mov eax,cur;
		//	push eax;
		//	call cvSub;
		//	add  esp,10h
		//}
		break;
		   }
	case 1:
		Detect(wrt, cur,Robert);
		break;
	case 2:
		Detect(wrt, cur,Prewitt);
		break;
	case 3:
		Detect(wrt, cur,LapLas);
		break;
	case 4:
		histogramNormalize(wrt, cur);
		break;
	case 5:
		histogramNormalize(pImagePool[0], cur);
		Detect(wrt,pImagePool[0],Prewitt);
		break;
	case 6:
		{
			imgDFT(wrt, cur);
		}
		break;
	case 7:
		{
			Detect(wrt, cur,FreiChen);
			break;
		}
	case 8:
		{
			Filter(wrt, cur);
			break;
		}
	case 9:
		{

			transRGB2Gray( pImagePool[0], cur);
			Filter(wrt, pImagePool[0],averageFilter);

		}
	default:
		break;
	}

}
예제 #3
0
JNIEXPORT void JNICALL Java_com_jiangpeng_android_antrace_Utils_grayScale( JNIEnv* env, jobject thiz, jobject input, jobject output )
{
	AndroidBitmapInfo inputInfo;
	AndroidBitmapInfo outputInfo;
	int ret = 0;
	void* src_pixels = 0;
	void* dst_pixels = 0;

	if ((ret = AndroidBitmap_getInfo(env, input, &inputInfo)) < 0) {
		return;
	}

	if (inputInfo.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
		return;
	}
	if ((ret = AndroidBitmap_lockPixels(env, input, &src_pixels)) < 0) {
		return;
	}

	if ((ret = AndroidBitmap_getInfo(env, output, &outputInfo)) < 0) {
		return;
	}

	if (outputInfo.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {
		return;
	}
	if ((ret = AndroidBitmap_lockPixels(env, output, &dst_pixels)) < 0) {
		return;
	}

	int32_t histogram[256];
	memset( &histogram, 0, sizeof( int32_t ) * 256 );
	const int kShiftBits = 20;
	const int32_t kRedRatio = static_cast<int32_t>((1 << kShiftBits) * 0.21f);
	const int32_t kGreenRatio = static_cast<int32_t>((1 << kShiftBits) * 0.71f);
	const int32_t kBlueRatio = static_cast<int32_t>((1 << kShiftBits) * 0.07f);

	void* src_start = src_pixels;
	void* dst_start = dst_pixels;
	for (uint32_t scan_line = 0; scan_line < outputInfo.height; scan_line++) {
	    uint32_t* dst = reinterpret_cast<uint32_t*>(dst_pixels);
	    pixel32_t* src = reinterpret_cast<pixel32_t*>(src_pixels);
	    pixel32_t* src_line_end = src + inputInfo.width;
	    while (src < src_line_end) {
	    	int32_t src_red = src->rgba8[0];
	    	int32_t src_green = src->rgba8[1];
	    	int32_t src_blue = src->rgba8[2];
	    	int32_t src_alpha = src->rgba8[3];

	    	int32_t dst_color = (kRedRatio * src_red + kGreenRatio * src_green +
	    			kBlueRatio * src_blue) >> kShiftBits;
	    	if (dst_color > 255) {
	    		dst_color = 255;
	    	}
	    	*dst = (src_alpha << 24) | (dst_color << 16) | (dst_color << 8) | dst_color;
	    	unsigned char index = (unsigned char)*dst;
			histogram[index]++;
	    	dst++;
	    	src++;
	    }
	    dst_pixels = reinterpret_cast<char*>(dst_pixels) + outputInfo.stride;
	    src_pixels = reinterpret_cast<char*>(src_pixels) + inputInfo.stride;
	}

	unsharpMask(src_start, dst_start, outputInfo.width, outputInfo.height, inputInfo.stride, 5);
	histogramNormalize(src_start, dst_start, outputInfo.width, outputInfo.height, inputInfo.stride, histogram);

	AndroidBitmap_unlockPixels(env, input);
	AndroidBitmap_unlockPixels(env, output);
}
int main (int argc, char* argv[])
{
    int result = EXIT_SUCCESS;
    int flagExit = 0;
    int opt = 0;
    int flagInputSet = 0;
    int flagAnnotationSet = 0;
    char inputListFileName[1024] = {0};
    char annotationFileName[1024] = {0};
    char outputDirName[1024] = "./";
    int bin = 4;
    unsigned int maxFiles = INT_MAX;
    static struct option longopts[] =
    {
        {"help", no_argument, NULL, 'h'},
        {"input", required_argument, NULL, 'i'},
        {"annotation", required_argument, NULL, 'a'},
        {"max-file", required_argument, NULL, 'm'},
        {"output-dir", required_argument, NULL, 'd'},
        {"bin", required_argument, NULL, 'b'},
        {NULL, 0, NULL, 0}
    };

    while ((opt = getopt_long(argc, argv, "hi:a:m:d:b:", longopts, NULL)) != -1)
    {
        switch (opt)
        {
            case 'h':
                printUsage(argv[0]);
                flagExit = 1;
                break;
            case 'i':
                flagInputSet = 1;
                strncpy(inputListFileName, optarg, 1023);
                break;
            case 'a':
                flagAnnotationSet = 1;
                strncpy(annotationFileName, optarg, 1023);
                break;
            case 'm':
                maxFiles = atoi(optarg);
                break;
            case 'd':
                strncpy(outputDirName, optarg, 1023);
                break;
            case 'b':
                bin = atoi(optarg);
                break;
            case '?':
                break;
        }
    }

    if (flagExit == 0)
    {
        if (flagInputSet)
        {
            FILE *inputListFile = fopen(inputListFileName, "r");
            if (inputListFile == NULL)
            {
                fprintf(stderr, "Unable to open %s\n", argv[1]);
                result = EXIT_FAILURE;
            }
            else
            {
                char* outputFileName = (char*) malloc(
                    (strlen(outputDirName)+16)*sizeof(char));
                strcpy(outputFileName, outputDirName);
                FILE *SVMFile = fopen(strcat(outputFileName, "histo.svm"), "w");
                if (SVMFile == NULL)
                {
                    fprintf(stderr, "Unable to create %s\n", outputFileName);
                }
                else
                {
                    char url[1024] = {0};
                    CIMAGE *img = NULL;
                    Histogram *histo = NULL;
                    int counter = 0;
                    while (feof(inputListFile) == 0 && counter < maxFiles)
                    {
                        counter++;
                        if (fscanf(inputListFile, "%s\n", url) > 0)
                        {
                            img = loadCImage(url);
                            histo = histogramCreate(bin);
                            histogramCompute(img, histo);
                            histogramNormalize(histo);
                            histogramSaveAsSVM(histo, SVMFile);
                            histogramDestroy(&histo);
                            destroyCImage(&img);
                        }
                        if (counter % 50 == 0)
                        {
                            fprintf(stderr, "Images done : %d\n", counter);
                        }
                    }
                    fclose(SVMFile);
                }
                free(outputFileName);
                fclose(inputListFile);
            }
        }
        if (flagAnnotationSet)
        {
            char* SVMFileName = (char*) malloc(
                    (strlen(outputDirName)+16)*sizeof(char));
            strcpy(SVMFileName, outputDirName);
            FILE *SVMFile = fopen(strcat(SVMFileName, "histo.svm"), "r");
            if (SVMFile != NULL)
            {
                FILE *annotationFile = fopen(annotationFileName, "r");
                if (annotationFile != NULL)
                {
                    char* outputFileName = (char*) malloc(
                        (strlen(outputDirName)+strlen("annotated.svm")+1)*sizeof(char));
                        strcpy(outputFileName, outputDirName);
                    FILE *resultFile = fopen(strcat(outputFileName, "annotated.svm"), "w");   
                    if (resultFile != NULL)
                    {
                        int imgClass;
                        int counter = 0;
                        while (feof(annotationFile) == 0 && counter < maxFiles)
                        {
                            char strHisto[1024] = {0};
                            counter++;

                            if(fscanf(annotationFile, "%*d_%*d %d\n", &imgClass) > 0)
                            {
                                imgClass = imgClass > 0 ? 1 : -1;
                                if (fscanf(SVMFile, "0 %[0123456789.: ]\n", strHisto) > 0)
                                {
                                    fprintf(resultFile, "%d %s\n", imgClass, strHisto);
                                }
                            }
                            
                        }
                        fclose(resultFile);
                    }
                    else
                    {
                        fprintf(stderr, "Unable to create the annotated histograms file.\n");
                    }
                    fclose(annotationFile);
                }
                else
                {
                    fprintf(stderr, "Annotation file unreadable (does it exist ?)\n");
                }
                fclose(SVMFile);
            }
            else
            {
                fprintf(stderr, "SVMFile unreadable (does it exist ?)\n");
            }
        }
    }

    return result;
}