Skip to content
Snippets Groups Projects
Commit 83208093 authored by Sergi Hernandez's avatar Sergi Hernandez
Browse files

Added a new function to get the images using a provided buffer instead of creating a new one.

Solved a problem when publishing the mono image. It is a bayer image and not a mono image.
parent a3d39336
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,9 @@
#include <sstream>
#include <iostream>
const int num_frames=10;
//#define SHARED
const int num_frames=1000;
int main(int argc, char *argv[])
{
......@@ -39,8 +41,9 @@ int main(int argc, char *argv[])
event_server=CEventServer::instance();
ladybug->get_config(&left_off,&top_off,&width,&height,&framerate,&depth,&coding);
std::cout << "Fremerate: " << framerate << std::endl;
coding=RGB;
framerate=1;
coding=MONO;
depth=DEPTH8;
framerate=5;
ladybug->set_config(&left_off,&top_off,&width,&height,&framerate,depth,coding);
ladybug->get_multi_config(&width,&height,&framerate,&depth,&coding);
std::cout << "Image size: " << width << "x" << height << std::endl;
......@@ -48,18 +51,31 @@ int main(int argc, char *argv[])
std::cout << "Color coding: " << (int)coding << "-" << (int)depth << std::endl;
ladybug->get_new_frame_event_id(new_frame);
events.push_back(new_frame);
#ifdef SHARED
front=new char[width*height*depth/8];
front_right=new char[width*height*depth/8];
rear_right=new char[width*height*depth/8];
rear_left=new char[width*height*depth/8];
front_left=new char[width*height*depth/8];
top=new char[width*height*depth/8];
#endif
ladybug->start();
for ( i=0 ; i<num_frames ; i++ )
{
text.str("");
gettimeofday(&start_time,NULL);
event_server->wait_all(events,0);
event_server->wait_all(events,5000);
#ifdef SHARED
ladybug->get_images_shared(front,front_right,rear_right,rear_left,front_left,top);
#else
ladybug->get_images(&front,&front_right,&rear_right,&rear_left,&front_left,&top);
#endif
filename="image_";
text << i;
filename+=text.str();
filename+=".ppm";
ladybug->save_images(filename,front,front_right,rear_right,rear_left,front_left,top);
#ifndef SHARED
if(front!=NULL)
{
delete[] front;
......@@ -90,6 +106,7 @@ int main(int argc, char *argv[])
delete[] top;
top=NULL;
}
#endif
gettimeofday(&end_time,NULL);
elapsed_time[i]=(end_time.tv_sec-start_time.tv_sec)*1000000+end_time.tv_usec-start_time.tv_usec;
std::cout << "Elapsed time: " << elapsed_time[i] << "s" << std::endl;
......
......@@ -42,7 +42,13 @@ void CLadyBug::set_config(unsigned int *left_off,unsigned int *top_off,unsigned
this->set_framerate(framerate);
this->set_num_DMA_buffers(4);
if(coding==RGB || coding==MONO)
{
if(coding==RGB)
this->multi_depth=DEPTH24;
else
this->multi_depth=DEPTH8;
this->multi_coding=coding;
}
else
this->multi_coding=RGB;
}
......@@ -63,7 +69,7 @@ void CLadyBug::get_images(char **front, char **front_right, char **rear_right, c
dc1394video_frame_t *frame;
unsigned char *RGB_image;
if ( *front != NULL || *front_right != NULL || *rear_right != NULL || *rear_left != NULL || *front_left != NULL || *top != NULL)
if ( *front != NULL || *front_right != NULL || *rear_right != NULL || *rear_left != NULL || *front_left != NULL || *top != NULL)
{
DEBUG_INFO("Invalid image buffer.\n");
/* handle error */
......@@ -199,6 +205,118 @@ void CLadyBug::get_images(char **front, char **front_right, char **rear_right, c
}
}
void CLadyBug::get_images_shared(char *front, char *front_right, char *rear_right, char *rear_left, char *front_left, char *top)
{
int depth;
dc1394error_t error;
dc1394video_frame_t *frame;
unsigned char *RGB_image;
DEBUG_INFO("Capturing a new image ... ");
if ( this->one_shot_mode == DC1394_ON )
{
/* set the one shot mode */
DEBUG_INFO("Setting the one shot mode ... ");
error = dc1394_video_set_one_shot(this->camera_handle,DC1394_ON);
if ( error != DC1394_SUCCESS )
{
DEBUG_INFO("failed\n");
/* handle the error */
throw CFirewireInternalException(_HERE_,error);
}
DEBUG_INFO("ok\n");
DEBUG_INFO("Dequeuing a DMA buffer ... ");
error = dc1394_capture_dequeue(this->camera_handle,DC1394_CAPTURE_POLICY_WAIT,&frame);
if ( error != DC1394_SUCCESS )
{
DEBUG_INFO("failed\n");
/* handle error */
throw CFirewireInternalException(_HERE_,error);
}
if(this->multi_coding==RGB)
{
depth = (int)ceil((float)this->multi_depth/8.0);
RGB_image=new unsigned char[this->width*this->height*depth];
// extract color from the bayer tile image
// note: this will alias colors on the top and bottom rows
dc1394_bayer_decoding_8bit( (unsigned char *)frame->image,
RGB_image,
this->width,
this->height,
this->bayer_pattern,
DC1394_BAYER_METHOD_NEAREST);
memcpy(front,RGB_image,this->multi_width*this->multi_height*depth);
memcpy(front_right,RGB_image+this->multi_height*this->multi_width*depth,this->multi_width*this->multi_height*depth);
memcpy(rear_right,RGB_image+2*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(rear_left,RGB_image+3*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(front_left,RGB_image+4*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(top,RGB_image+5*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
delete[] RGB_image;
}
else
{
depth = (int)ceil((float)this->depth/8.0);
memcpy(front,(unsigned char *)frame->image,this->multi_width*this->multi_height*depth);
memcpy(front_right,(unsigned char *)frame->image+this->multi_height*this->multi_width*depth,this->multi_width*this->multi_height*depth);
memcpy(rear_right,(unsigned char *)frame->image+2*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(rear_left,(unsigned char *)frame->image+3*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(front_left,(unsigned char *)frame->image+4*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(top,(unsigned char *)frame->image+5*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
}
if(this->frame_buffer!=NULL)
delete[] this->frame_buffer;
depth = (int)ceil((float)this->depth/8.0);
this->frame_buffer = new char[this->width*this->height*depth];
memcpy(this->frame_buffer,frame->image,this->width*this->height*this->depth/8.0);
DEBUG_INFO("ok\n");
DEBUG_INFO("Freeing the DMA buffer ... ");
error = dc1394_capture_enqueue(this->camera_handle,frame);
if ( error != DC1394_SUCCESS )
{
DEBUG_INFO("failed\n");
/* handle error */
throw CFirewireInternalException(_HERE_,error);
}
DEBUG_INFO("ok\n");
}
else
{
this->image_access.enter();
if(this->multi_coding==RGB)
{
depth = (int)ceil((float)this->multi_depth/8.0);
RGB_image=new unsigned char[this->width*this->height*depth];
// extract color from the bayer tile image
// note: this will alias colors on the top and bottom rows
dc1394_bayer_decoding_8bit( (unsigned char *)this->frame_buffer,
RGB_image,
this->width,
this->height,
this->bayer_pattern,
DC1394_BAYER_METHOD_NEAREST);
memcpy(front,RGB_image,this->multi_width*this->multi_height*depth);
memcpy(front_right,RGB_image+this->multi_height*this->multi_width*depth,this->multi_width*this->multi_height*depth);
memcpy(rear_right,RGB_image+2*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(rear_left,RGB_image+3*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(front_left,RGB_image+4*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(top,RGB_image+5*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
delete[] RGB_image;
}
else
{
depth = (int)ceil((float)this->depth/8.0);
memcpy(front,(unsigned char *)this->frame_buffer,this->multi_width*this->multi_height*depth);
memcpy(front_right,(unsigned char *)this->frame_buffer+this->multi_height*this->multi_width*depth,this->multi_width*this->multi_height*depth);
memcpy(rear_right,(unsigned char *)this->frame_buffer+2*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(rear_left,(unsigned char *)this->frame_buffer+3*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(front_left,(unsigned char *)this->frame_buffer+4*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
memcpy(top,(unsigned char *)this->frame_buffer+5*(this->multi_height*this->multi_width*depth),this->multi_width*this->multi_height*depth);
}
this->image_access.exit();
}
}
void CLadyBug::save_images(std::string &filename,char *front, char *front_right, char *rear_right, char *rear_left, char *front_left, char *top)
{
std::string header,name;
......
......@@ -47,6 +47,11 @@ class CLadyBug : public CPTGCamera
*
*/
void get_images(char **front, char **front_right, char **rear_right, char **rear_left, char **front_left, char **top);
/**
* \brief
*
*/
void get_images_shared(char *front, char *front_right, char *rear_right, char *rear_left, char *front_left, char *top);
/**
* \brief
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment