Example #1
0
void UsbCam::grab_image(sensor_msgs::Image* msg)
{
  // grab the image
  image_ = (camera_image_t *)calloc(1, sizeof(camera_image_t));
  image_->width = RAW_IMAGE_WIDTH;
  image_->height = RAW_IMAGE_HEIGHT;
  image_->bytes_per_pixel = 3;
  image_->image_size = RAW_IMAGE_HEIGHT*RAW_IMAGE_WIDTH*3;
  image_->is_new = 0;
  image_->image = (char *)calloc(image_->image_size, sizeof(char));
  memset(image_->image, 0, image_->image_size * sizeof(char));
  grab_image();
  // stamp the image
  msg->header.stamp = ros::Time::now();
  // fill the info
  //if (monochrome_)
  //{
  //  fillImage(*msg, "mono8", image_->height, image_->width, image_->width,
  //      image_->image);
  //}
  //else
  //{
    fillImage(*msg, "rgb8", image_->height, image_->width, 3 * image_->width,
        image_->image);
  //}
}
void send_image_info(struct pico_socket *s)
{

	IplImage* temp= grab_image(config.scale_factor, config.color_disable);
	int bytes=-1;
	uint16_t image_attrib[NUMBER_OF_ATTRIB];

	image_attrib[0]= temp->width;
	image_attrib[1]= temp->height;
	image_attrib[2]= temp->nChannels;
	image_attrib[3]= temp->depth;

	bytes= pico_socket_sendto(s, (void*)image_attrib, NUMBER_OF_ATTRIB*sizeof(image_attrib[0]), &peer, port);
	if(bytes < 0) {
		printf("Pico socket write failed. error = %i\n", pico_err);
		exit(-1);
	}

	printf("\n\nimg WIDTH: %i\n", temp->width);
	printf("img HEIGHT: %i\n", temp->height);
	printf("img nchannels: %i\n", temp->nChannels);
	printf("img depth: %i\n\n", temp->depth);


	printf("info about img sent\n");
}
unsigned char*
grab_raw_data(const double scale, const int convert_grayscale, int* imagesize)
{
	IplImage *image = grab_image(scale, convert_grayscale);

	if(!image) {
		printf("Grab image failed.\n");
		return NULL;
	}
	
	*imagesize = image->imageSize;
	
	cvGetRawData(image, &raw_data, NULL, NULL);

	return raw_data;
}