Exemple #1
0
int main(int args,char *argv[]){
	IplImage *inputImage;
	IplImage *outputImage;
	cvNamedWindow("inputImage",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("inputImage",100,100);
	cvNamedWindow("outputImage",CV_WINDOW_AUTOSIZE);
	cvMoveWindow("outputImage",200,200);
	//
	printf("%s",argv[1]);
	assert(argv[1]);
	// 只有灰度图才可以canny
	inputImage = cvLoadImage(argv[1],CV_LOAD_IMAGE_GRAYSCALE);
	cvShowImage("inputImage",inputImage);
	// float lowThresh 内部轮廓。数字越大越模糊
	// float highThresh //外部轮廓。数字越大越模糊
	// float aperture
	outputImage = canny(inputImage,100,100,3);
	cvShowImage("outputImage",outputImage);
	cvWaitKey(0);
	//
	cvDestroyWindow("outputImage");
	cvDestroyWindow("inputImage");
	cvReleaseImage(&outputImage);
	cvReleaseImage(&inputImage);
	return 0;
}
Exemple #2
0
Rhythm::Rhythm(float inputSampleRate)
    : Plugin(inputSampleRate) {
  m_sampleRate = inputSampleRate;
  numBands = 7;
  bandHighFreq = NULL;
  calculateBandFreqs();

  // calculate and save half-hanny window
  halfHannLength = 12;
  halfHannWindow = new float[halfHannLength];
  for (int i = 0; i < halfHannLength; i++)
    halfHannWindow[i] = halfHanning((float) i);

  // calculate and save canny window
  cannyLength = 12;
  cannyShape = 4.f;
  cannyWindow = new float[cannyLength * 2 + 1];
  for (int i = cannyLength * -1; i < cannyLength + 1; i++)
    cannyWindow[i + cannyLength] = canny((float) i);

  // set up parameters
  threshold = 1;
  average_window = 200;
  peak_window = 6;
  max_bpm = 300;
  min_bpm = 12;
}
int main(int argc, char** argv)
{
	int arg;
	IplImage* img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
	IplImage* out = 0;
	printf("Chose an operation:-\n0 - Blur\n1 - Pyre\n2 - Canny\n3 - Grey");
	scanf("%d",&arg);
	printf("%d\n",arg);
	if(arg == 0)
	out = blur(img);
	else if(arg == 1)
	out = pyre(img, 2,2);
	else if(arg == 2)
	out = canny(img, 10,100,3);
	else
        out = gray(img);
	

	cvNamedWindow("Example7-In",CV_WINDOW_AUTOSIZE);
	cvNamedWindow("Example7-Out",CV_WINDOW_AUTOSIZE);

	cvShowImage("Example7-In", img);
	cvShowImage("Example7-Out", out);
	
	cvWaitKey(0);

	cvReleaseImage(&img);
	cvReleaseImage(&out);

	cvDestroyWindow("Example7-In");
	cvDestroyWindow("Example7-Out");
	return(0);
}
Exemple #4
0
int main()
{
  int width = 2048;
  int height = 2048;
  
  float * input = new float[width*height];
  float * output = new float[width*height];
  
  for( int i = 0 ; i < height ; i++) 
    for( int j = 0 ; j < width ; j++ ){
      input[i*width+j] = (rand()%256)/ 5.0;
    }
  
  milliseconds time(0);

  bool useDevMem = false;
  if (const char *var = getenv("FORMA_USE_DEVICE_MEMORY")) {
    useDevMem = (atoi(var) != 0);
  }
  
  float* inputPtr = input;
  if (useDevMem) {
    cudaMalloc(&inputPtr, sizeof(float)*width*height);
    cudaMemcpy(inputPtr, input, sizeof(float)*width*height, cudaMemcpyHostToDevice);
  }


  canny(inputPtr,height,width,output);
  if (check_error(input,height,width,output) < 0)
    return -1;


  for( int i = 0 ; i < _NTRIALS_ ; i++ ){
    auto start = HighResolutionClock::now();
    canny(inputPtr,height,width,output);
    auto stop = HighResolutionClock::now();
    time += std::chrono::duration_cast<milliseconds>(stop-start);
  }
  printf("[FORMA] Total Time(ms) : %lf\n",(double)time.count()/_NTRIALS_);

  if (useDevMem)
    cudaFree(inputPtr);

  delete[] input;
  delete[] output;
  return 0;
}
void EdgeHistogram::InitializeImage(const vigra::FVector3Image& image) {
	// Consider grayscale image
	vigra::FImage image_gray(image.width(), image.height());
	vigra::transformImage(srcImageRange(image), destImage(image_gray),
		VectorMeanTransformAccessor<vigra::FVector3Image::Accessor>());

	// 1. Compute canny edge image
	vigra::BImage canny(image_gray.width(), image_gray.height());
	canny = 0;
	vigra::cannyEdgeImage(srcImageRange(image_gray), destImage(canny),
		1, 15, 255);	// scale, threshold, edgevalue
	//vigra::exportImage(srcImageRange(canny), "canny.png");

	// 2. Get gradient magnitude and orientation of original image
	vigra::FVector2Image gradient(canny.width(), canny.height());
	vigra::gradientBasedTransform(srcImageRange(image_gray),
		destImage(gradient),
		MagnitudeOrientationGradientFunctor<float>(undirected_edges));

	// 3. Produce matrices: histogram bin and gradient magnitude for each pixel
	bin_image.resize(gradient.height(), gradient.width());
	gmm::fill(bin_image, 0);
	bin_value.resize(gradient.height(), gradient.width());
	gmm::fill(bin_value, 0);
	for (int y = 0; y < gradient.height(); ++y) {
		for (int x = 0; x < gradient.width(); ++x) {
			// No edge -> skip
			if (canny(x, y) == 0)
				continue;

			// Edge: calculate bin index and gradient magnitude
			double magnitude = gradient(x, y)[0];
			double orientation = gradient(x, y)[1];	// range 0 to 1.
			assert(orientation >= 0.0 && orientation <= 1.0);
			if (orientation >= 1.0)
				orientation = 0.0;
			orientation *= static_cast<double>(bin_count);
			int orientation_index = static_cast<int>(orientation) % bin_count;

			// Bin value of zero denotes no edge.
			bin_image(y, x) = orientation_index + 1;
			bin_value(y, x) = magnitude;
		}
	}
}
void MainWindow::cannySlot()
{	
	int high = QInputDialog::getInt(this,"High Threshold value","High Threshold value");
	int low = QInputDialog::getInt(this,"Low Threshold value","Low Threshold value");
	
	image = canny(image,low,high);
	
	setImages();
}
Exemple #7
0
//! Connect Image Processing Actions to Slots Methods
//!
void ImageView::connectActionToSlots()
{
  connect(ui->actionMid_Filter_2, SIGNAL(triggered()), this, SLOT(median_smoooth()));
  connect(ui->actionGaussian, SIGNAL(triggered()), this, SLOT(gaussian_smooth()));
  connect(ui->actionBilateral_Smooth,SIGNAL(triggered()), this, SLOT(bilateral_smooth()));
  connect(ui->actionGLCM, SIGNAL(triggered()), this, SLOT(gLCM()));
  connect(ui->actionCanny, SIGNAL(triggered()), this, SLOT(canny()));
  connect(ui->actionLecel_Set, SIGNAL(triggered()), this, SLOT(levelSetSegmentation()));
  connect(ui->actionVideo_Camera_Track, SIGNAL(triggered()), this, SLOT(videoCameraTrack()));
}
Exemple #8
0
int main( int argc, char * argv[] )
{
	typedef mist::rgb< unsigned char >    pixel_type;
	typedef mist::array2< pixel_type >    color_image_type;
	typedef mist::array2< unsigned char > gray_image_type;
	typedef mist::vector2< double >       vector_type;

	if( argc < 2 )
	{
		std::cerr << "This program requires a path to an input image." << std::endl;
		return( 1 );
	}

	color_image_type orginal_img;
	color_image_type  canny_img;

	if( !read_image( orginal_img, argv[ 1 ] ) )
	{
		std::cerr << "Could not open the image [" << argv[ 1 ] << "]." << std::endl;
		return( 1 );
	}

	// エッジを検出する
	canny( orginal_img, canny_img, 100, 200 );

	// Hough変換により直線のパラメータを求める
	std::vector< std::complex< double > > lines;
	mist::line::hough_transform( canny_img, lines, 100, 1, 3.1415926535897932384626433832795 / 360.0, 200 );

	// 直線を描画する
	double scale = orginal_img.width( ) > orginal_img.height( ) ? orginal_img.width( ) : orginal_img.height( );
	for( size_t i = 0 ; i < lines.size( ) ; i++ )
	{
		double rho = lines[ i ].real( );
		double theta = lines[ i ].imag( );

		vector_type p1( std::cos( theta ) * rho, std::sin( theta ) * rho );
		vector_type p2( p1.x - rho * std::sin( theta ), p1.y + rho * std::cos( theta ) );
		vector_type d = ( p2 - p1 ).unit( );

		p1 -= d * scale;
		p2 += d * scale;

		int x1 = static_cast< int >( p1.x + 0.5 );
		int y1 = static_cast< int >( p1.y + 0.5 );
		int x2 = static_cast< int >( p2.x + 0.5 );
		int y2 = static_cast< int >( p2.y + 0.5 );

		mist::draw_line( orginal_img, x1, y1, x2, y2, mist::colors< pixel_type >::red( ) );
	}

	write_image( orginal_img, "output.png" );

	return( 0 );
}
Exemple #9
0
JNIEXPORT void JNICALL Java_com_jiminger_image_canny_EdgeDetectorOpImage_canny
(JNIEnv * env, jobject /*this*/, jint destwidth, jint destheight, 
 jbyteArray dest, jint /*destOffset*/, jint /*destPixelStride*/, jint /*destScanlineStride*/,
 jbyteArray src, jint /*srcOffset*/, jint /*srcPixelStride*/, jint /*srcScanLineStride*/,
 jfloat lowThreshold, jfloat highThreshold, jfloat sigma, jbyte noedgeval,
 jbyte edgeval, jbyte possibleEdge,
 jbyteArray gradDirImData
// jfloatArray gradDirImData
 )
{
//   printf(" destwidth = %ld\n", destwidth);
//   printf(" destheight = %ld\n", destheight);
//   printf(" destOffset = %ld\n",destOffset);
//   printf(" destPixelStride = %ld\n", destPixelStride);
//   printf(" destScanlineStride = %ld\n", destScanlineStride);
//   printf(" srcOffset = %ld\n",srcOffset);
//   printf(" srcPixelStride = %ld\n", srcPixelStride);
//   printf(" srcScanLineStride = %ld\n", srcScanLineStride);

   jboolean isCopy;
   jbyte* srcData = 
      (jbyte*)(env->GetPrimitiveArrayCritical(src, &isCopy));

   jbyte* destData = 
      (jbyte*)(env->GetPrimitiveArrayCritical(dest, &isCopy));

   jbyte* gradDirIm =
      (gradDirImData != NULL) ? 
      (jbyte*)(env->GetPrimitiveArrayCritical(gradDirImData, &isCopy)) :
      NULL;

//   jfloat* gradDirIm =
//      (gradDirImData != NULL) ? 
//      (jfloat*)(env->GetPrimitiveArrayCritical(gradDirImData, &isCopy)) :
//      NULL;

   NOEDGE = (unsigned char)noedgeval;
   EDGE = (unsigned char)edgeval;
   POSSIBLE_EDGE = (unsigned char)possibleEdge;

   canny((unsigned char*)srcData, destheight, destwidth, (float)sigma,
         (float)lowThreshold, (float)highThreshold, 
         (unsigned char*)destData, (unsigned char*)gradDirIm);


   if (gradDirIm != NULL)
      env->ReleasePrimitiveArrayCritical(gradDirImData,gradDirIm,0);

   env->ReleasePrimitiveArrayCritical(dest,destData,0);
   env->ReleasePrimitiveArrayCritical(src,srcData,0);

}
/*
 *  mexFunction:  Matlab entry function into this C++ code
 *  Inputs: 
 *      int nlhs:   Number of left hand arguments (output)
 *      mxArray *plhs[]:   The left hand arguments (output)
 *      int nrhs:   Number of right hand arguments (inputs)
 *      const mxArray *prhs[]:   The right hand arguments (inputs)
 *
 * Notes:
 *      (Left)  goes_out = foo(goes_in);    (Right)
 */
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{

	image8	im_in, im_out;
	float sigma = 2.0;		/* Standard deviation of the gaussian kernel. */
	float tlow = 0.3;       /* Fraction of the high threshold in hysteresis. */ 
	float thigh = 0.7;      /* High hysteresis threshold control. The actual
								threshold is the (100 * thigh) percentage point
								in the histogram of the magnitude of the
								gradient image that passes non-maximal suppression. */
	
	int inputProc = 0;
	char *cmd, dbg[128];

	if (nrhs == 0) {
		help();
		return;
	}

	for (inputProc = 0; inputProc < nrhs; ) {
		getStr( &prhs[inputProc++], &cmd );
		//mexPrintf("Cmd = %s\n",cmd);
		
		if (strcmp(cmd,"image")==0) {
			getData( &prhs[inputProc++], &im_in );
		} else if(strcmp(cmd,"sigma")==0) {
			sigma = (float) getDblRetDbl( &prhs[inputProc++] );
		} else if(strcmp(cmd,"tlow")==0) {
			tlow = (float) getDblRetDbl( &prhs[inputProc++] );
		} else if(strcmp(cmd,"thigh")==0) {
			thigh = (float) getDblRetDbl( &prhs[inputProc++] );
		}else if(strcmp(cmd,"help")==0 || strcmp(cmd,"HELP")==0){
			help();
			return;
		} else {
			sprintf(dbg,"%s is not a valid command...\n",cmd);
			mexErrMsgTxt( dbg );
		}
		mxFree( cmd );
	}

	canny(im_in.im, im_in.dims[1], im_in.dims[0], sigma, tlow, thigh, &(im_out.im));
	im_out.dims[0] = im_in.dims[0];
	im_out.dims[1] = im_in.dims[1];
	
	//Send the edged image back to Matlab.
    sendData( &plhs[0], &im_out);
    
    free( im_in.im );
    free( im_out.im );
}
Exemple #11
0
int main(int argc, char** argv){
    FILE* inputImage=fopen(argv[1],"rb");
    FILE* outputMagnitudes=fopen(argv[2],"wb");
    FILE* outputPeaks=fopen(argv[3],"wb");
    FILE* outputFinal=fopen(argv[4],"wb");
    double sigma = atof(argv[5]);
    
    Record record;
    fread(&record, sizeof(record), 1, inputImage);
    fwrite(&record, sizeof(record), 1, outputMagnitudes);
    fwrite(&record, sizeof(record), 1, outputPeaks);
    fwrite(&record, sizeof(record), 1, outputFinal);

    canny(inputImage, outputMagnitudes, outputPeaks, outputFinal, sigma);
}
Exemple #12
0
QVector<int> hysteresis(int width, int height,
                        const QVector<int> &image)
{
    QVector<int> canny(image);

    for (int y = 0; y < height; y++)
        for (int x = 0; x < width; x++)
            trace(width, height, canny, x, y);

    // Remaining gray pixels becomes black.
    for (int i = 0; i < canny.size(); i++)
        if (canny[i] == 127)
            canny[i] = 0;

    return canny;
}
static void do_canny(lti::gaussianPyramid<lti::image> &imgPyramid,
		     std::vector<lti::channel8*> &edges,
		     double minSharpness) {
  uint64_t start_time_in_ms;
  uint64_t end_time_in_ms;

  struct timeval tv;

  gettimeofday(&tv, NULL);
  start_time_in_ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;

  // params
  lti::cannyEdges::parameters cannyParam;
  if (minSharpness == 0) {
    cannyParam.thresholdMax = 0.04;
  } else {
    cannyParam.thresholdMax = 0.10 + 0.90 * ((minSharpness - 1) / 4.0);
  }
  cannyParam.thresholdMin = 0.04;
  cannyParam.kernelSize = 7;

  // run
  lti::cannyEdges canny(cannyParam);
  g_assert(edges.size() == 0);

  for (int i = 0; i < imgPyramid.size(); i++) {
    fprintf(stderr, "canny[%d]: %dx%d\n", i, imgPyramid[i].columns(),
	   imgPyramid[i].rows());
    lti::channel8 *c8 = new lti::channel8;
    canny.apply(imgPyramid[i], *c8);
    edges.push_back(c8);
  }

  gettimeofday(&tv, NULL);
  end_time_in_ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
  fprintf(stderr, "canny done in %ju ms\n", end_time_in_ms - start_time_in_ms);
}
int main(int argc, char* argv[]){
	// Load input video
	cv::VideoCapture input_cap(argv[1]);
	if (!input_cap.isOpened()){
		std::cout << "!!! Input video could not be opened" << std::endl;
		return -1;
	}

	// Setup output video
	cv::VideoWriter output_cap;
	output_cap.open("output.avi",  
		(int)CV_FOURCC('X','V','I','D'),
		input_cap.get(CV_CAP_PROP_FPS), 
		cv::Size(input_cap.get(CV_CAP_PROP_FRAME_WIDTH), input_cap.get(CV_CAP_PROP_FRAME_HEIGHT)),false); //true for color image
														// false for gray image

	if (!output_cap.isOpened()){
		std::cout << "!!! Output video could not be opened" << std::endl;
		return -1;
	}

	// Loop to read frames from the input capture and write it to the output capture
	cv::Mat frame;
	cv::Mat can;
	while (true){
		if (!input_cap.read(frame))             
			break;
		canny(frame,can);
		output_cap.write(frame);
	        output_cap.write(frame);
	}

	input_cap.release();
	output_cap.release();

	return 0;
}
Exemple #15
0
int main( int argc, char * argv[] )
{
	const char * WINDOW_NAME = "Original Image";

	// x is low
	// y is high
	std::pair< int, int > thresh = std::make_pair( THRESH_MIN, THRESH_MAX);

	if( argc < 2 )
	{
		std::cerr << "Not enough parameters.\n";
		exit( -1 );
	}
	ImageRAII image( argv[1] );

	cvNamedWindow( WINDOW_NAME );
	cvShowImage( WINDOW_NAME, image.image );
	cvMoveWindow( WINDOW_NAME, 0, 0 );

	ImageRAII edge_detection_image = canny( image.image, thresh, SIGMA );

	cvWaitKey( 0 );
	return 0;
}
main(int argc, char *argv[])
{
   char *infilename = NULL;  /* Name of the input image */
   char *dirfilename = NULL; /* Name of the output gradient direction image */
   char outfilename[128];    /* Name of the output "edge" image */
   char composedfname[128];  /* Name of the output "direction" image */
   unsigned char *image;     /* The input image */
   unsigned char *edge;      /* The output edge image */
   int rows, cols;           /* The dimensions of the image. */
   float sigma,              /* Standard deviation of the gaussian kernel. */
	 tlow,               /* Fraction of the high threshold in hysteresis. */
	 thigh;              /* High hysteresis threshold control. The actual
			        threshold is the (100 * thigh) percentage point
			        in the histogram of the magnitude of the
			        gradient image that passes non-maximal
			        suppression. */

   /****************************************************************************
   * Get the command line arguments.
   ****************************************************************************/
   if(argc < 5){
   fprintf(stderr,"\n<USAGE> %s image sigma tlow thigh [writedirim]\n",argv[0]);
      fprintf(stderr,"\n      image:      An image to process. Must be in ");
      fprintf(stderr,"PGM format.\n");
      fprintf(stderr,"      sigma:      Standard deviation of the gaussian");
      fprintf(stderr," blur kernel.\n");
      fprintf(stderr,"      tlow:       Fraction (0.0-1.0) of the high ");
      fprintf(stderr,"edge strength threshold.\n");
      fprintf(stderr,"      thigh:      Fraction (0.0-1.0) of the distribution");
      fprintf(stderr," of non-zero edge\n                  strengths for ");
      fprintf(stderr,"hysteresis. The fraction is used to compute\n");
      fprintf(stderr,"                  the high edge strength threshold.\n");
      fprintf(stderr,"      writedirim: Optional argument to output ");
      fprintf(stderr,"a floating point");
      fprintf(stderr," direction image.\n\n");
      exit(1);
   }

   infilename = argv[1];
   sigma = atof(argv[2]);
   tlow = atof(argv[3]);
   thigh = atof(argv[4]);

   if(argc == 6) dirfilename = infilename;
   else dirfilename = NULL;

   /****************************************************************************
   * Read in the image. This read function allocates memory for the image.
   ****************************************************************************/
   if(VERBOSE) printf("Reading the image %s.\n", infilename);
   if(read_pgm_image(infilename, &image, &rows, &cols) == 0){
      fprintf(stderr, "Error reading the input image, %s.\n", infilename);
      exit(1);
   }

   /****************************************************************************
   * Perform the edge detection. All of the work takes place here.
   ****************************************************************************/
   if(VERBOSE) printf("Starting Canny edge detection.\n");
   if(dirfilename != NULL){
      sprintf(composedfname, "%s_s_%3.2f_l_%3.2f_h_%3.2f.fim", infilename,
      sigma, tlow, thigh);
      dirfilename = composedfname;
   }
   canny(image, rows, cols, sigma, tlow, thigh, &edge, dirfilename);

   /****************************************************************************
   * Write out the edge image to a file.
   ****************************************************************************/
   sprintf(outfilename, "%s_s_%3.2f_l_%3.2f_h_%3.2f.pgm", infilename,
      sigma, tlow, thigh);
   if(VERBOSE) printf("Writing the edge iname in the file %s.\n", outfilename);
   if(write_pgm_image(outfilename, edge, rows, cols, "", 255) == 0){
      fprintf(stderr, "Error writing the edge image, %s.\n", outfilename);
      exit(1);
   }
   
}
int main(int argc, char *argv[])
{
    char *infilename = NULL;  /* Name of the input image */
    char *dirfilename = NULL; /* Name of the output gradient direction image */
    char outfilename[128];    /* Name of the output "edge" image */
    char composedfname[128];  /* Name of the output "direction" image */
    unsigned char *image;     /* The input image */
    unsigned char *edge;      /* The output edge image */
    int rows, cols;           /* The dimensions of the image. */
    float sigma=2.5,              /* Standard deviation of the gaussian kernel. */
          tlow=0.5,               /* Fraction of the high threshold in hysteresis. */
          thigh=0.5;              /* High hysteresis threshold control. The actual
			        threshold is the (100 * thigh) percentage point
			        in the histogram of the magnitude of the
			        gradient image that passes non-maximal
			        suppression. */

    /****************************************************************************
    * Get the command line arguments.
    ****************************************************************************/
    if(argc < 2)
    {
        fprintf(stderr,"\n<USAGE> %s image sigma tlow thigh [writedirim]\n",argv[0]);
        fprintf(stderr,"\n      image:      An image to process. Must be in ");
        fprintf(stderr,"PGM format.\n");
        exit(1);
    }

    infilename = argv[1];

    Timer totalTime;
    initTimer(&totalTime, "Total Time");

    /****************************************************************************
    * Read in the image. This read function allocates memory for the image.
    ****************************************************************************/
    if(VERBOSE) printf("Reading the image %s.\n", infilename);
    if(read_pgm_image(infilename, &image, &rows, &cols) == 0)
    {
        fprintf(stderr, "Error reading the input image, %s.\n", infilename);
        exit(1);
    }

    /****************************************************************************
    * Perform the edge detection. All of the work takes place here.
    ****************************************************************************/
    if(VERBOSE) printf("Starting Canny edge detection.\n");
    if(dirfilename != NULL)
    {
        sprintf(composedfname, "%s_s_%3.2f_l_%3.2f_h_%3.2f.fim", infilename,
                sigma, tlow, thigh);
        dirfilename = composedfname;
    }

    
 //   MCPROF_START();
    canny(image, rows, cols, sigma, tlow, thigh, &edge, dirfilename);
   // MCPROF_STOP();
    
    


    /****************************************************************************
    * Write out the edge image to a file.
    ****************************************************************************/
    sprintf(outfilename, "%s_s_%3.2f_l_%3.2f_h_%3.2f.pgm", infilename,
            sigma, tlow, thigh);
    if(VERBOSE) printf("Writing the edge iname in the file %s.\n", outfilename);
    if(write_pgm_image(outfilename, edge, rows, cols, "", 255) == 0)
    {
        fprintf(stderr, "Error writing the edge image, %s.\n", outfilename);
        exit(1);
    }

    free(image);
    free(edge);
    return 0;
}
Exemple #18
0
int edgedetect(int j,unsigned int* total)
{
  int i = 0;
  int k = 0;
  int averow = 0;
  int avecol = 0;
  int diffrow = 0;
  int diffcol = 0;
  int confirmed = 0;
  int confirmed2 = 0;
  int position = 0;

  unsigned char rows[100];
  unsigned char cols[100];
  unsigned char rows2[100];
  unsigned char cols2[100];

  unsigned char numberofhits[1] = {0};
  //savegreyscale(j);

  canny(j);

  for(i=0;i<59;i++)
  {
      for(k=0;k<33;k++)
      {
          if(numberofhits[0]==100)
          {
              return 1;
          }

          cornerdetect(img.pixel_data,i,k,numberofhits,rows,cols);
      }
  }

  if(numberofhits[0]>0)
  {
      for(i=0;i<numberofhits[0];i++)
      {
            averow = averow + rows[i];
            avecol = avecol + cols[i];
      }

      averow = averow/numberofhits[0];
      avecol = avecol/numberofhits[0];

      for(i=0;i<numberofhits[0];i++)
      {
          diffrow = abs(averow-rows[i]);
          diffcol = abs(avecol-cols[i]);
          if(diffcol < 6 && diffrow < 6)
          {
              rows2[position] = rows[i];
              cols2[position] = cols[i];
              confirmed2 = confirmed2 + 1;
              position = position + 1;

          }
      }

      numberofhits[0] = confirmed2;
  }

  averow = 0;
  avecol = 0;

  if(numberofhits[0]>0)
  {
      for(i=0;i<numberofhits[0];i++)
      {
            averow = averow + rows2[i];
            avecol = avecol + cols2[i];
            printf(" %d %d ",rows2[i],cols2[i]);
      }

      averow = averow/numberofhits[0];
      avecol = avecol/numberofhits[0];

      for(i=0;i<numberofhits[0];i++)
      {
          diffrow = abs(averow-rows2[i]);
          diffcol = abs(avecol-cols2[i]);
          if(diffcol < 4 && diffrow < 4)
          {
              confirmed = confirmed + 1;
              total[0] = total[0] + 1;
          }
      }

      numberofhits[0] = confirmed;
  }


  printf("\nResults\n\nHits: %d \nConfirmed: %d \n\n",numberofhits[0],confirmed);
  return 0;
}
Exemple #19
0
int Masek::findline(Masek::IMAGE *image, double **lines)
{
	
	filter *I2, *orND, *I3, *I4, *edgeimage;
	double theta[180];
	double *R, *xp;
	double maxval;
	int size, linecount;
	double cx, cy;
	int i, j, index, x, y;
	double r, t;
	int tmpcount;
	FILE *fid;

	fid = fopen("image.txt", "w");
	for (i = 0; i<image->hsize[0]; i++)
	{
		for (j = 0; j<image->hsize[1]; j++)
			fprintf(fid, "%d %d %d\n", i+1, j+1, image->data[i*image->hsize[1]+j]);
		
	}
	fclose(fid);
	
	I2 = (filter*)malloc(sizeof(filter));
	orND = (filter*)malloc(sizeof(filter));

	
	image = canny(image, 2, 1, 0.00, 1.00, I2, orND);
	//imwrite("C:\\testImage090716.bmp", image);	

	/*fid = fopen("I2.txt", "w");
	for (i = 0; i<I2->hsize[0]; i++)
	{
		for (j = 0; j<I2->hsize[1]; j++)
			fprintf(fid, "%d %d %f\n", i+1, j+1, I2->data[i*I2->hsize[1]+j]);		
	}
	fclose(fid);

	fid = fopen("or.txt", "w");
	for (i = 0; i<or->hsize[0]; i++)
	{
		for (j = 0; j<or->hsize[1]; j++)
			fprintf(fid, "%d %d %f\n", i+1, j+1, or->data[i*or->hsize[1]+j]);
		
	}
	fclose(fid);*/


	I3 = adjgamma(I2, 1.9);
	/*fid = fopen("I3.txt", "w");
	for (i = 0; i<I3->hsize[0]; i++)
	{
		for (j = 0; j<I3->hsize[1]; j++)
			fprintf(fid, "%d %d %f\n", i+1, j+1, I3->data[i*I3->hsize[1]+j]);
		
	}
	fclose(fid);*/

	I4 = nonmaxsup(I3, orND, 1.5);

	/*fid = fopen("I4.txt", "w");
	for (i = 0; i<I4->hsize[0]; i++)
	{
		for (j = 0; j<I4->hsize[1]; j++)
			fprintf(fid, "%d %d %f\n", i+1, j+1, I4->data[i*I4->hsize[1]+j]);
		
	}
	fclose(fid);*/
	
	edgeimage = hysthresh(I4, 0.20, 0.15);
  //edgeimage = hysthresh(I4, 0.25, 0.10);//LEE:
	

	for (i = 0; i<180; i++)
		theta[i] = i;

	/*fid = fopen("edge.txt", "w");
	for (i = 0; i<edgeimage->hsize[0]; i++)
	{
		for (j = 0; j<edgeimage->hsize[1]; j++)
			fprintf(fid, "%d %d %f\n", i+1, j+1, edgeimage->data[i*edgeimage->hsize[1]+j]);
		
	}
	fclose(fid);*/

	size = radonc(edgeimage->data, theta, edgeimage->hsize[0], edgeimage->hsize[1], 180, &R, &xp);

	
	/*fid = fopen("r.txt", "w");
	for (i = 0; i<size; i++)
	{
		for (j = 0; j<180; j++)
			fprintf(fid, "%d %d %f\n", i+1, j+1, R[i*180+j]);
		
	}
	fclose(fid);
	fid = fopen("xp.txt", "w");
	for (i = 0; i<size; i++)
	{
		fprintf(fid, "%f\n", xp[i]);
		
	}
	fclose(fid);
	*/
	
	maxval = -1;
	index = -1;


	linecount=0;
	for (i = 0; i<size*180; i++)
	{
		if (R[i]>maxval)
		{
			maxval = R[i];
			index = i;
			linecount=1;
		}
		else if (R[i]==maxval)
		{
			linecount++;
		}
	}

	if (maxval<=25)
		return 0;

	
	*lines = (double*) malloc(sizeof(double)*linecount*3);
	

	cx = image->hsize[1]/2.0-1;
	cy = image->hsize[0]/2.0-1;

	tmpcount=0;
	
	for (i = index; i<size*180; i++)
	{
		if (R[i]==maxval)
		{
			y = i/180;
			x = i%180;
			t = -theta[x]*PI/180;
			r = xp[y];
			
			(*lines)[tmpcount*3] = cos(t);
			(*lines)[tmpcount*3+1] = sin(t);
			(*lines)[tmpcount*3+2] = -r;
			(*lines)[tmpcount*3+2] = (*lines)[tmpcount*3+2] - (*lines)[tmpcount*3]*cx - (*lines)[tmpcount*3+1]*cy;
			tmpcount++;
		}
	}

	free(R);
	free(xp);
	free(I2->data);
	free(I2);
	free(orND->data);
	free(orND);
	return linecount;
}