Exemplo n.º 1
0
static void *
malloc_buffer_map(struct pb_buffer *buf, 
                  unsigned flags,
		  void *flush_ctx)
{
   return malloc_buffer(buf)->data;
}
Exemplo n.º 2
0
struct buffer *replace_prefix_line(struct buffer *buff, const char *prefix, int prefix_size, const char *new_line, int new_line_size)
{
	char *p, *end_p, *q;
	struct buffer *new_buff;

	p = find_prefix_line(buff, prefix, prefix_size);
	if (p == NULL)
	{
		return NULL;
	}

	end_p = find_next_line(buff, p);
	if (end_p == NULL)
	{
		new_buff = malloc_buffer(buff->size + new_line_size + 1);
	}
	else
	{
		new_buff = malloc_buffer(buff->size - (end_p - p) + new_line_size + 1);
	}

	if (new_buff == NULL)
	{
		return NULL;
	}

	q = mem_area_copy(mem_area_copy(new_buff->space, buff->space, p - 1), new_line, new_line + new_line_size - 1);

	if (end_p == NULL)
	{
		return new_buff;
	}

	*q++ = '\n';
	mem_area_copy(q, end_p, buff->space + buff->size - 1);

	return new_buff;
}
Exemplo n.º 3
0
struct buffer *read_lines(const char *file_path)
{
	struct stat st;
	struct buffer *buff;
	int ret;
	int fd;

	fd = open(file_path, O_RDONLY | O_BINARY);
	if (fd < 0)
	{
		perror("open");
		return NULL;
	}

	ret = fstat(fd, &st);
	if (ret < 0)
	{
		perror("fstat");
		goto out_close_file;
	}

	buff = malloc_buffer(st.st_size);
	if (buff == NULL)
	{
		perror("malloc_buffer");
		goto out_close_file;
	}

	ret = ffile_read(fd, buff->space, buff->size);
	if (ret < 0)
	{
		perror("ffile_read");
		goto out_free_buff;
	}

	close(fd);

	return buff;

out_free_buff:
	free_buffer(buff);
out_close_file:
	close(fd);

	return NULL;
}
Exemplo n.º 4
0
int
main(int argc, char **argv)
{
  if ( argc < 3 ) {
    printf("Usage: %s <object-image-file.png> <scene-image-file.png>\n", argv[0]);
    exit(-1);
  }

  const char *object_file = argv[1];
  const char *scene_file = argv[2];

  printf("QASiftppClassifier: creating cvImages for object and scene\n");
  IplImage * obj_img = cvLoadImage( object_file, 1 );
  IplImage * scn_img = cvLoadImage( scene_file, 1 );
  //IplImage * stacked = stack_imgs( obj_img, scn_img );

  printf("QASiftppClassifier: Load scene as image\n");
  /*
  JpegReader *reader = new JpegReader(scene_file);
  */
  PNGReader *reader = new PNGReader(scene_file);
  unsigned char *buffer = malloc_buffer(YUV422_PLANAR,
					reader->pixel_width(), reader->pixel_height());
  reader->set_buffer(buffer);
  reader->read();

  //  PNGWriter pngw("scenetest.png", reader->pixel_width(), reader->pixel_height());
  //  pngw.set_buffer(YUV422_PLANAR, buffer );
  //  pngw.write();


  printf("QASiftppClassifier: Instantiate SiftppClassifier\n");
  SiftppClassifier *classifier = new SiftppClassifier(object_file);

  classifier->set_src_buffer(buffer, reader->pixel_width(), reader->pixel_height());

  printf("QASiftppClassifier: classify ...\n");
  std::list< ROI > *rois = classifier->classify();

  printf("QASiftppClassifier: filterROI\n");
  FilterROIDraw *roi_draw = new FilterROIDraw();
  for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) {
    printf("QASiftppClassifier: ROI: start (%u, %u)  extent %u x %u\n", 
	   (*i).start.x, (*i).start.y, (*i).width, (*i).height);
    // draw ROIs
    roi_draw->set_dst_buffer(buffer, &(*i));
    roi_draw->apply();
  }

  printf("QASiftppClassifier: draw ROIs in cvWindow\n");
  for (std::list< ROI >::iterator i = rois->begin(); i != rois->end(); ++i) {
    if( (*i).height == 11 && (*i).width == 11 ) {
      cvRectangle( scn_img, 
		   cvPoint((*i).start.x, (*i).start.y), 
		   cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height), 
		   CV_RGB( 0, 0, 180 ), 
		   2//, 4
		   );
    }
    else{
      cvRectangle( scn_img, 
		   cvPoint((*i).start.x, (*i).start.y), 
		   cvPoint((*i).start.x+(*i).width, (*i).start.y+(*i).height), 
		   CV_RGB( 180, 0, 0 ), 
		   2//, 4
		   );
    }
  }

  //display_big_img( stacked, "Matches" );
  cvNamedWindow( "Scene-Matches", 1 );
  cvShowImage( "Scene-Matches", scn_img );
  cvNamedWindow( "Object", 1 );
  cvShowImage( "Object", obj_img );
  cvWaitKey( 0 );

  //  ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
  //  display->show(buffer);
  //  display->loop_until_quit();
  //  delete display;

  delete rois;
  free(buffer);
  delete reader;
  delete classifier;
}
Exemplo n.º 5
0
static void
malloc_buffer_destroy(struct pb_buffer *buf)
{
   align_free(malloc_buffer(buf)->data);
   FREE(buf);
}