Exemplo n.º 1
0
/**
    \fn getNextFrame
*/
bool         Msharpen::getNextFrame(uint32_t *fn,ADMImage *image)
{
ADMImage *src,*blur,*dst;

    src=vidCache->getImage(nextFrame);
    if(!src)
        return false; // EOF
    
    blur=blurrImg;
    dst=image;

    dst->Pts=src->Pts;
	
    for (int i=0;i<3;i++)
    {
            
            blur_plane(src, blur, i);
            detect_edges(blur, dst,  i);
            if (_param.highq == true)
                detect_edges_HiQ(blur, dst,  i);
            if (!_param.mask) 
                apply_filter(src, blur, dst,  i);
    }

    *fn=nextFrame;
    nextFrame++;
    vidCache->unlockAll();
    return true;
}
/**
    \fn getNextFrame
*/
bool         Msharpen::getNextFrame(uint32_t *fn,ADMImage *image)
{
ADMImage *src,*blur,*dst;
/*
	PVideoFrame src = child->GetFrame(n, env);
	PVideoFrame blur = env->NewVideoFrame(vi);
	PVideoFrame dst = env->NewVideoFrame(vi);
*/
unsigned char *blurp;
unsigned char *dstp;

	dst=image;
	src=vidCache->getImage(nextFrame);
    if(!src)
        return false; // EOF
	blur=blurrImg;
    dst->Pts=src->Pts;
	{
		for (int i=0;i<3;i++)
		{
            blurp=blur->GetReadPtr((ADM_PLANE)i);
			blur_plane(src, blur, blurp ,i);
            dstp=dst->GetWritePtr((ADM_PLANE)i);
			detect_edges(blur, dst, dstp, i);
			if (_param.highq == true)
				detect_edges_HiQ(blur, dst, dstp, i);

			if (!_param.mask) apply_filter(src, blur, dst, dstp, i);
		}
	}
    *fn=nextFrame;
    nextFrame++;
	vidCache->unlockAll();
	return true;
}
Exemplo n.º 3
0
int main (int argc, char* argv[]) {

  if (argc != 4) { 
    std::cerr << "Usage: segment [minsize] [threshold] [Image file]\n";
    return -1;
  }
  int threshold = atoi(argv[2]);
  int seg_size = atoi(argv[1]);

  //Load image from input file
  JPG_RGBImage image(argv[3]);
  EdgeMap edges(image.height(), image.width());

  detect_edges(&edges, &image, threshold);

  //int32_t* pix_count;
  struct edge_img_info* infos;
  //int32_t total_colors = color_components(&edges, &pix_count, &infos);

  int32_t total_colors = color_components(&edges, &infos);


  for (int color = 2, img_num = 0; total_colors > color; color++) {
    //printf ("region %d has %d pixels\n", color, pix_count[color]);
    if (seg_size <= infos[color].numpixels) {
      //printf ("region %d has %d pixels\n", color, pix_count[color]);
      
      if (-1 == write_new_image (image, edges, color, img_num++,infos[color])) {
        //free (pix_count);
        free (infos);
        return 3;
      }
    }
  }

}
  void imageCb(const sensor_msgs::ImageConstPtr& msg)
  {

    cv_bridge::CvImagePtr cv_ptr;
    namespace enc = sensor_msgs::image_encodings;

    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("cv_bridge exception: %s", e.what());
      return;
    }

    // Draw an example circle on the video stream
    if (cv_ptr->image.rows > 400 && cv_ptr->image.cols > 600){

	detect_edges(cv_ptr->image);
    	image_pub_.publish(cv_ptr->toImageMsg());

	}
  }
Exemplo n.º 5
0
// relock
void MyGlWindow::relock ( double max_dihedral_angle, int nruns )
{
	// lookup LUT
	_LUT.lookup( _camera->came.getTranslation(), MIN_SUBTENDED_ANGLE, 0.0, 100, 0);

	int i;

	printf("detecting edges\n");

	// detect edges
	detect_edges();

	// distribute visible edges into buckets
	std::vector< intVector > edges_buckets;
	distribute_edgeplanes_into_buckets( edges_buckets );

	// compute the region size on the tessellatio
	printf("computing region\n");

	int level = 1 + max_dihedral_angle / SPHERE_TESSELLATION_RESOLUTION;
	LOG(LEVEL_INFO, "region size: %d", level);

	int N = _LUT._lines.size();

	printf("converting lines\n");
	// convert the model lines into edgeplanes in the camera coordinate frame
	edgePlaneVector lines_edgeplanes;
	intVector line_ids;
	for (i=0;i<N;i++) {
		Vec3d a = _camera->fromWorldFrameToCameraFrame( _LUT._lines[i]->getA() );
		Vec3d b = _camera->fromWorldFrameToCameraFrame( _LUT._lines[i]->getB() );
		Vec3d s = Vec3d(0,0,0);
		lines_edgeplanes.push_back( EdgePlane( a, b, s, -1, _LUT._lines[i]->_id, i ) );
		line_ids.push_back( _LUT._lines[i]->_id );
	}

	corresVector correspondences;

	// clear the state machine
	SM_Clear();

	// for each model line, search the possible matches
	for (i=0;i<N;i++) {

		EdgePlane line = lines_edgeplanes[i];

		intVector cells;
		get_edgeplane_buckets( line, cells );

		// create a correspondence
		corres c ( _LUT._lines[i] );

		for (int m=0;m<cells.size();m++) {

			int bucket_id = cells[m];

			for (int j=0;j<edges_buckets[bucket_id].size();j++) {

				int edge_id = edges_buckets[bucket_id][j];

				EdgePlane edge;
				if (!_camera->_frame.get_edgeplane_chained( edge_id, edge ) ) {
					LOG(LEVEL_ERROR, "error accessing edgeplane %d out of %d edgeplanes.", edge_id, _camera->_frame.n_edgeplanes_chained );
					continue;
				}

				double angle = line.angle( edge );

				if ( angle > max_dihedral_angle ) 
					continue;

				c.eps.push_back( edge );
			}

			if ( c.valid() ) {
				correspondences.push_back( c );
				SM_InsertItem( c );
			}
		}
	}

	ExtrinsicParameters original_pose = _camera->getPose();
	ExtrinsicParameters best_pose = original_pose;
	double best_score = score_camera_pose( original_pose, edges_buckets );
	
	LOG(LEVEL_INFO, "start score: %f", best_score );
	
	// find the best camera pose possible
	for (int run=0; run < nruns; run++) {

		// reset camera pose
		_camera->setPose( original_pose );

		// draw random correspondences
		CorrespondenceVector cs;

		intVector indices;
		selectNRandomInt( 5/*INIT_MIN_CORRESPONDENCES*/, SM_Size(), indices);

		// for each correspondence, pick a choice randomly
		for (i=0;i<indices.size();i++) {
			Correspondence d;
			d.first = SM_Get(indices[i]).line;
			int p = MIN( SM_Get(indices[i]).eps.size()-1, (double)rand() / (RAND_MAX+1) * (SM_Get(indices[i]).eps.size()-1));
			d.second = SM_Get(indices[i]).eps[p];
			cs.push_back( d );
		}

		refineCameraPoseFromNCorrespondences( cs );

		double score = score_camera_pose( _camera->getPose(), edges_buckets );

		if ( score > best_score ) {

			best_score = score;
			best_pose = _camera->getPose();
		}	
	}

	// keep the best camera pose found so far
	_camera->setPose( best_pose );

	LOG(LEVEL_INFO, "new score: %f", best_score );

	// clear the state machine
	SM_Clear();

	// populate correspondences again
	correspondences.clear();
	init_correspondences( correspondences, edges_buckets, MAINTENANCE_DIHEDRAL_ANGLE, MAINTENANCE_MIN_OVERLAP, true );
}
int main(int argc, char *argv[])
{
	FILE *ifile, *ofile, *ofile2;
	const char *ofname, *ofname2;
	Image *img;
	unsigned char *edge_pix;
	PList *edge_pts;
	float threshold, radius;
#ifdef MTRACE
	setenv("MALLOC_TRACE", "mtrace.out", 0);
	mtrace();
#endif
	// check args
	if (argc < 2)
	{
		fprintf(stderr, "Usage: %s IN.bmp [BLUR_RADIUS [THRESHOLD [OUT.bmp [POINTS.txt]]]]\n", argv[0]);
		return 1;
	}

	// open input image
	ifile = fopen(argv[1], "r");
	if (!ifile)
	{
		fprintf(stderr, "Error opening '%s'.\n", argv[1]);
		return 1;
	}

	// read input image
	img = Image_createFromBMP(ifile);
	fclose(ifile);
	if (!img) { LOG("Image_createFromBMP failed"); return -1; }

	// read blur radius
	radius = (argc >= 3) ? atof(argv[2]) : -1.f;
	if (!isfinite(radius) || radius < 0.f)
	{
		radius = 5.f;
		fprintf(stderr, "Using default blur radius: %g\n", radius);
	}

	// read threshold
	threshold = (argc >= 4) ? atof(argv[3]) : -1.f;
	if (!isfinite(threshold) || threshold < 0.f)
	{
		threshold = 10.f;
		fprintf(stderr, "Using default threshold: %g\n", threshold);
	}

	// open output image
	ofname = (argc >= 5) ? argv[4] : "out.bmp";
	ofile = fopen(ofname, "wb");
	if (!ofile) fprintf(stderr, "Error opening '%s'.\n", ofname);

	// open output points file
	ofname2 = (argc >= 6) ? argv[5] : "pts.txt";
	ofile2 = fopen(ofname2, "w");
	if (!ofile2) fprintf(stderr, "Error opening '%s'.\n", ofname2);

	// create output structures
	edge_pix = (unsigned char *) malloc(img->w * img->h);
	if (!edge_pix) { LOG("alloc edge_pix failed"); return -1; }
	edge_pts = PList_create();
	if (!edge_pts) LOG("alloc edge_pts failed");

	// find edge pixels
timer_start();
struct timeval tmp = start_time; // hack so other calls don't affect main timer

	detect_edges(img, radius, threshold, edge_pix, edge_pts);

start_time = tmp; elapsed = 0.0;
timer_end("detect_edges");

	// write output image (edge pixels)
	if (ofile && edge_pix)
	{
		grayscale_writeBMP(edge_pix, img->w, img->h, ofile);
		fclose(ofile);
	}

	// write list of edge points
	if (ofile2 && edge_pts)
	{
		int i, n = edge_pts->len;
		for (i = 0; i < n; i++)
		{
			P p = edge_pts->pts[i];
			fprintf(ofile2, "%04d,%04d\n", p.y, p.x);
		}
		fclose(ofile2);
	}

	// cleanup
	Image_free(img);
	free(edge_pix);
	PList_free(edge_pts);
#ifdef MTRACE
	muntrace();
#endif
	return 0;
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
  po::options_description opt_desc("Edge detection client. Available options");

  opt_desc.add_options()
    ("dataset-path,d",
     po::value<std::string>()->default_value("../images/e1088_mag1_small"),
     "Specify path to dataset in Knossos format.")
    ("cross-section-x1",
     po::value<int>()->default_value(50),
     "Cross section dimensions. X coordinate of top-left corner.")
    ("cross-section-y1",
     po::value<int>()->default_value(50),
     "Cross section dimensions. Y coordinate of top-left corner.")
    ("cross-section-x2",
     po::value<int>()->default_value(320),
     "Cross section dimensions. X coordinate of bottom-right corner.")
    ("cross-section-y2",
     po::value<int>()->default_value(320),
     "Cross section dimensions. Y coordinate of bottom-right corner.")
    ("cross-section-z",
     po::value<int>()->default_value(120),
     "Cross section dimensions. Z coordinate of cross-section plane.")
    ("gaussian_sigma", po::value<float>()->default_value(0.8408964), "")
    ("sup_rad1", po::value<int>(), "")
    ("sup_rad2", po::value<int>(), "")
    ("thresh_high1", po::value<int>(), "")
    ("thresh_high2", po::value<int>(), "")
    ("thresh_diff1", po::value<int>(), "")
    ("thresh_diff2", po::value<int>(), "")
    ("ep1", po::value<float>(), "")
    ("ep2", po::value<float>(), "")
    ("ep3", po::value<float>(), "")
    ("thresh_ray", po::value<int>(), "")
    ("union_ray", po::value<int>(), "")
    ("print_compounds", po::value<bool>(), "")
    ("do_matching", po::value<bool>(), "")
    ;

  options opts(opt_desc, argc, argv);

  dataset d(opts.string_var("dataset-path"));

  image i = cross_section_z(d,
                            opts.int_var("cross-section-x1"),
                            opts.int_var("cross-section-x2"),
                            opts.int_var("cross-section-y1"),
                            opts.int_var("cross-section-y2"),
                            opts.int_var("cross-section-z"));

  {
    std::cerr
      << "Exporting original image to output/edge-detection/original.pgm."
      << std::endl;

    pgm_export(i, boost::filesystem::path("../output/edge-detection/original.pgm"));
  }

  image magnified = gaussian(i, opts.float_var("gaussian_sigma"));

  {
    std::cerr
      << "Exporting blurred image to output/edge-detection/blurred.pgm."
      << std::endl;

    pgm_export(magnified, boost::filesystem::path("../output/edge-detection/blurred.pgm"));
  }
  

  {
    std::stringstream coords;
    coords << opts.int_var("cross-section-x1") << "#";
    coords << opts.int_var("cross-section-x2") << "#";
    coords << opts.int_var("cross-section-y1") << "#";
    coords << opts.int_var("cross-section-y2") << "#";
    coords << opts.int_var("cross-section-z") << "#";
    
    int sup_rad1 = opts.int_var("sup_rad1");
    int sup_rad2 = opts.int_var("sup_rad2");
    int thresh_high1 = opts.int_var("thresh_high1");
    int thresh_high2 = opts.int_var("thresh_high2");
    int thresh_diff1 = opts.int_var("thresh_diff1");
    int thresh_diff2 = opts.int_var("thresh_diff2");
    for(int supp_radius = sup_rad1; supp_radius <= sup_rad2; supp_radius++)
      for(int thigh = thresh_high1; thigh <= thresh_high2; thigh += 10)
        for(int tlow = thigh-thresh_diff1; tlow <= thigh-thresh_diff2; tlow += 10)
          {
            image i_edge_detection;
	    rgb_image i_before_join;
	    rgb_image i_after_join;
	    std::tie(i_edge_detection, i_before_join, i_after_join)
	      = detect_edges(magnified,thigh,tlow,supp_radius,0,
		       opts.float_var("ep1"),
		       opts.float_var("ep2"),
		       opts.float_var("ep3"),
		       opts.bool_var("print_compounds"),
		       opts.bool_var("do_matching"),
		       opts.int_var("union_ray"),
		       opts.int_var("thresh_ray"),
		       coords.str()
		       );
	    {
              std::stringstream ss;
              ss << "../output/edge-detection/edge_detection" << thigh << "_"<< tlow << "_" << supp_radius << ".pgm";

              std::cerr << "Exporting image to " << ss.str() << std::endl;
              pgm_export(i_edge_detection, boost::filesystem::path(ss.str()));
            }

            {
              std::stringstream ss;
              ss << "../output/edge-detection/edge_detection" << thigh << "_"<< tlow << "_" << supp_radius << "before.ppm";

              std::cerr << "Exporting image to " << ss.str() << std::endl;
              ppm_export(i_before_join, boost::filesystem::path(ss.str()));
            }
	    
	    {
              std::stringstream ss;
              ss << "../output/edge-detection/edge_detection" << thigh << "_"<< tlow << "_" << supp_radius << "after.ppm";

              std::cerr << "Exporting image to " << ss.str() << std::endl;
              ppm_export(i_after_join, boost::filesystem::path(ss.str()));
            }
          }
    
  }

  std::cerr << "Program finished successfully." << std::endl;

  return 0;
}