| 1 | // %flair:license{
|
---|
| 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
| 4 | // %flair:license}
|
---|
| 5 | // created: 2014/03/06
|
---|
| 6 | // filename: Camera.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: Virtual class for Camera
|
---|
| 14 | //
|
---|
| 15 | //
|
---|
| 16 | /*********************************************************************/
|
---|
| 17 |
|
---|
| 18 | #include "Camera.h"
|
---|
| 19 | #include <FrameworkManager.h>
|
---|
| 20 | #include <Tab.h>
|
---|
| 21 | #include <TabWidget.h>
|
---|
| 22 | #include <GroupBox.h>
|
---|
| 23 | #include <GridLayout.h>
|
---|
| 24 | #include <DataPlot1D.h>
|
---|
| 25 | #include <Picture.h>
|
---|
| 26 | #include <Buffer.h>
|
---|
| 27 | #include <highgui.h>
|
---|
| 28 | #include <fstream>
|
---|
| 29 |
|
---|
| 30 | using std::string;
|
---|
| 31 | using namespace flair::core;
|
---|
| 32 | using namespace flair::gui;
|
---|
| 33 |
|
---|
| 34 | namespace flair {
|
---|
| 35 | namespace sensor {
|
---|
| 36 |
|
---|
| 37 | Camera::Camera(const FrameworkManager *parent, string name, uint16_t width,
|
---|
| 38 | uint16_t height, cvimage::Type::Format format)
|
---|
| 39 | : IODevice(parent, name) {
|
---|
| 40 | plot_tab = NULL;
|
---|
| 41 | jpgBuffer=NULL;
|
---|
| 42 | logFormat=LogFormat::NONE;
|
---|
| 43 |
|
---|
| 44 | // do not allocate imagedata, allocation is done by the camera
|
---|
| 45 | output = new cvimage((IODevice *)this, width, height, format, "out", false);
|
---|
| 46 |
|
---|
| 47 | // station sol
|
---|
| 48 | main_tab = new Tab(parent->GetTabWidget(), name);
|
---|
| 49 | tab = new TabWidget(main_tab->NewRow(), name);
|
---|
| 50 | sensor_tab = new Tab(tab, "Setup");
|
---|
| 51 | setup_groupbox = new GroupBox(sensor_tab->NewRow(), name);
|
---|
| 52 | setup_layout = new GridLayout(sensor_tab->NewRow(), "setup");
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | //This contructor must only be called for a simulated device.
|
---|
| 56 | Camera::Camera(const IODevice *parent, std::string name)
|
---|
| 57 | : IODevice(parent, name) {
|
---|
| 58 | plot_tab = NULL;
|
---|
| 59 | main_tab = NULL;
|
---|
| 60 | tab = NULL;
|
---|
| 61 | sensor_tab = NULL;
|
---|
| 62 | setup_groupbox = NULL;
|
---|
| 63 |
|
---|
| 64 | output = NULL;
|
---|
| 65 | jpgBuffer=NULL;
|
---|
| 66 | logFormat=LogFormat::NONE;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | Camera::~Camera() {
|
---|
| 70 | if (main_tab != NULL)
|
---|
| 71 | delete main_tab;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | void Camera::SetLogFormat(LogFormat logFormat) {
|
---|
| 75 | this->logFormat=logFormat;
|
---|
| 76 | switch(logFormat) {
|
---|
| 77 | case LogFormat::RAW:
|
---|
| 78 | AddDataToLog(output);
|
---|
| 79 | Warn("raw log of cvimage is not yet implemented\n");
|
---|
| 80 | break;
|
---|
| 81 | case LogFormat::JPG:
|
---|
| 82 | if(jpgBuffer==NULL) {
|
---|
| 83 | jpgBuffer=new Buffer(this,"jpg_bufer");
|
---|
| 84 | AddDataToLog(jpgBuffer);
|
---|
| 85 | }else{
|
---|
| 86 | Warn("log format already defined\n");
|
---|
| 87 | }
|
---|
| 88 | break;
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | DataType const &Camera::GetOutputDataType() const {
|
---|
| 93 | return output->GetDataType();
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | GroupBox *Camera::GetGroupBox(void) const { return setup_groupbox; }
|
---|
| 97 |
|
---|
| 98 | GridLayout *Camera::GetLayout(void) const { return setup_layout; }
|
---|
| 99 |
|
---|
| 100 | void Camera::UseDefaultPlot(const core::cvimage *image) {
|
---|
| 101 | if (tab == NULL) {
|
---|
| 102 | Err("not applicable for simulation part.\n");
|
---|
| 103 | return;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | plot_tab = new Tab(tab, "Picture");
|
---|
| 107 | Picture *plot = new Picture(plot_tab->NewRow(), ObjectName(), image);
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | Tab *Camera::GetPlotTab(void) const { return plot_tab; }
|
---|
| 111 |
|
---|
| 112 | uint16_t Camera::Width(void) const { return output->GetDataType().GetWidth(); }
|
---|
| 113 |
|
---|
| 114 | uint16_t Camera::Height(void) const {
|
---|
| 115 | return output->GetDataType().GetHeight();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | core::cvimage *Camera::Output(void) { return output; }
|
---|
| 119 |
|
---|
| 120 | void Camera::ProcessUpdate(core::io_data* data) {
|
---|
| 121 | switch(logFormat) {
|
---|
| 122 | case LogFormat::JPG:
|
---|
| 123 | ajouter compression jpg
|
---|
| 124 | break;
|
---|
| 125 | }
|
---|
| 126 | IODevice::ProcessUpdate(data);
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | void Camera::SaveToFile(string filename) const {
|
---|
| 130 | Printf("saving %s, size %i\n", filename.c_str(), output->img->imageSize);
|
---|
| 131 | std::ofstream pFile;
|
---|
| 132 | pFile.open(filename);
|
---|
| 133 | output->GetMutex();
|
---|
| 134 | pFile.write(output->img->imageData, output->img->imageSize);
|
---|
| 135 | output->ReleaseMutex();
|
---|
| 136 |
|
---|
| 137 | pFile.close();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | } // end namespace sensor
|
---|
| 141 | } // end namespace flair
|
---|