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

Added a function to get the bayer pattern of the sensor.

Added a function to get the image data with a provied pointer.
parent 34c208a3
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
unsigned int left_off,top_off;
depths_t depth;
codings_t coding;
int i=0;
int i=0,bayer_pattern;
std::list<std::string> event_list;
float framerate=30;
char *image=NULL;
......@@ -47,6 +47,8 @@ int main(int argc, char *argv[])
camera1->get_config(&left_off,&top_off,&width,&height,&framerate,&depth,&coding);
camera1->set_config(&left_off,&top_off,&width,&height,&framerate,depth,coding);
std::cout << framerate << std::endl;
camera1->get_bayer_pattern((dc1394color_filter_t *)&bayer_pattern);
std::cout << bayer_pattern << std::endl;
/* start continuous acquisition */
camera1->start();
for ( i=0 ; i<num_frames ; i++ )
......
......@@ -9,6 +9,7 @@
#include <math.h>
#include <sstream>
#include <iostream>
#include <dc1394/register.h>
CFirewireCamera::CFirewireCamera(dc1394_t *firewire,uint64_t camera_id)
{
......@@ -1545,6 +1546,64 @@ void CFirewireCamera::get_image(char **image)
}
}
void CFirewireCamera::get_image_shared(char *image)
{
int depth;
dc1394error_t error;
dc1394video_frame_t *frame;
if ( image != NULL)
{
DEBUG_INFO("Invalid image buffer.\n");
/* handle error */
throw CFirewireCameraException(_HERE_,"Invalid image buffer. Please provide an unallocated memory buffer.");
}
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);
}
depth = (int)ceil((float)this->depth/8.0);
if(this->frame_buffer!=NULL)
delete[] this->frame_buffer;
this->frame_buffer = new char[this->width*this->height*depth];
memcpy(image,frame->image,this->width*this->height*depth);
memcpy(this->frame_buffer,frame->image,this->width*this->height*depth);
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();
depth = (int)ceil((float)this->depth/8.0);
memcpy(image,this->frame_buffer,this->width*this->height*depth);
this->image_access.exit();
}
}
#ifdef HAVE_OPENCV_H
void CFirewireCamera::get_image(cv::Mat &image)
{
......@@ -1661,6 +1720,19 @@ void CFirewireCamera::get_new_frame_event_id(std::string& event_id)
event_id=this->new_frame_event_id;
}
void CFirewireCamera::get_bayer_pattern(dc1394color_filter_t *pattern)
{
dc1394error_t error;
error=dc1394_format7_get_color_filter(this->camera_handle,this->mode,pattern);
if ( error != DC1394_SUCCESS )
{
DEBUG_INFO("failed\n");
/* handle error */
throw CFirewireInternalException(_HERE_,error);
}
}
void CFirewireCamera::set_num_DMA_buffers(int num)
{
dc1394error_t error;
......
......@@ -1059,6 +1059,11 @@ class CFirewireCamera
*
*/
void get_image(char **image);
/**
* \brief
*
*/
void get_image_shared(char *image);
#ifdef HAVE_OPENCV_H
/**
* As get_image() but returns an OpenCV2.0-c++-like image
......@@ -1164,6 +1169,11 @@ class CFirewireCamera
*
*/
void get_new_frame_event_id(std::string& event_id);
/**
* \brief
*
*/
void get_bayer_pattern(dc1394color_filter_t *pattern);
/**
* \brief Function to show the general information of the associated camera
*
......
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