Esempio n. 1
0
int mainTextDetection ( int argc, char * * argv )
{

  DetectionParams params = detection_default_params;

  char* input_filename = argv[1];
  char* output_filename = argv[2];
  if (atoi(argv[3]) > -1)
    params.dark_on_light = atoi(argv[3]);
  if (atoi(argv[4]) > -1)
    params.canny_size = atoi(argv[4]);
  if (atof(argv[5]) > -1)
    params.canny_low = atof(argv[5]);
  if (atof(argv[6]) > -1)
    params.canny_high = atof(argv[6]);
  if (atoi(argv[7]) > -1)
    params.save_intermediate = atoi(argv[7]);


  IplImage * byteQueryImage = loadByteImage ( input_filename );
  if ( !byteQueryImage )
  {
    printf ( "couldn't load query image\n" );
    return -1;
  }

  // Detect text in the image
  IplImage * output = textDetection ( byteQueryImage, params );
  cvReleaseImage ( &byteQueryImage );

  // save output
  cvSaveImage ( output_filename, output );
  cvReleaseImage ( &output );
  return 0;
}
int mainTextDetection ( int argc, char** argv )
{
 

  IplImage* byteQueryImage = loadByteImage ( argv[1] );

  if ( !byteQueryImage )
  {
    printf ( "couldn't load query image\n" );
    return -1;
  }

  // Detect text in the image

  IplImage* output1 = textDetection ( byteQueryImage, 0 );
  IplImage* output11 = cvCreateImage( cvGetSize ( byteQueryImage ) , IPL_DEPTH_8U , 1 );
  IplImage* im_bw = cvCreateImage( cvGetSize ( byteQueryImage ) , IPL_DEPTH_8U , 1 );
  cvCvtColor (output1, output11, CV_RGB2GRAY);  
  cvThreshold(output11, im_bw, 128, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); 
  IplImage* output2 = textDetection ( byteQueryImage, 1);
  IplImage* output22 = cvCreateImage( cvGetSize ( byteQueryImage ) , IPL_DEPTH_8U , 1 );
  IplImage* im_bw2 = cvCreateImage( cvGetSize ( byteQueryImage ) , IPL_DEPTH_8U , 1 );
  cvCvtColor (output2, output22, CV_RGB2GRAY);  
  cvThreshold(output22, im_bw2, 128, 255, CV_THRESH_BINARY | CV_THRESH_OTSU); 
  IplImage* output = cvCreateImage( cvGetSize ( byteQueryImage ) , IPL_DEPTH_8U , 1 );

  cvZero( output );
   	
	// Computing the Color Greying Over Pixels
	int baseIndx = -( output11->widthStep );
	int greyBaseIndx = - (output->widthStep);
	
	for( int y = 0 ; y < ( output11->height ) ; ++y )
	{
		// Update the Base Indices
		baseIndx = baseIndx + ( output11->widthStep );
		greyBaseIndx = greyBaseIndx + (output->widthStep);

		// Set the Current Indices
		int currIndx = baseIndx - 1;
		int currIndxGrey = greyBaseIndx - 1;

		// Looping Over the Columns
		for( int x = 0 ; x < ( output11->width ) ; ++x )
		{
			// Update the Current Indices
			currIndx = currIndx + 1;
			currIndxGrey = currIndxGrey + 1;			


			int value1 = (unsigned char) im_bw->imageData[ currIndx ];
			int value2 = (unsigned char) im_bw2->imageData[ currIndx ];
			int value3;
			if(value1 < value2 )
				value3 = value1;
			else
				value3 = value2;
			
            output->imageData[currIndxGrey] = (char)(value3);
			
			//if( red1<255 or green1 <255 or blue1<255)
			//printf("%d %d %d \n", red1,green1,blue1);
		}
	}
  	
  //cvReleaseImage ( &byteQueryImage );
  cvSaveImage ( argv[2], im_bw );
  //cvReleaseImage ( &im_bw );
  cvSaveImage ( argv[3], im_bw2 );
  //cvReleaseImage ( &im_bw2 );
  //cvSaveImage ( argv[4], output );
  //cvReleaseImage ( &output );
  cvSaveImage ( argv[4], output);
  cvReleaseImage ( &output );
  
  
  return 0;
}