[3] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[3] | 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 <highgui.h>
|
---|
| 27 | #include <fstream>
|
---|
| 28 |
|
---|
| 29 | using std::string;
|
---|
| 30 | using namespace flair::core;
|
---|
| 31 | using namespace flair::gui;
|
---|
| 32 |
|
---|
[15] | 33 | namespace flair {
|
---|
| 34 | namespace sensor {
|
---|
[3] | 35 |
|
---|
[15] | 36 | Camera::Camera(const FrameworkManager *parent, string name, uint16_t width,
|
---|
| 37 | uint16_t height, cvimage::Type::Format format)
|
---|
| 38 | : IODevice(parent, name) {
|
---|
| 39 | plot_tab = NULL;
|
---|
[3] | 40 |
|
---|
[15] | 41 | // do not allocate imagedata, allocation is done by the camera
|
---|
| 42 | output = new cvimage((IODevice *)this, width, height, format, "out", false);
|
---|
[3] | 43 |
|
---|
[15] | 44 | // station sol
|
---|
| 45 | main_tab = new Tab(parent->GetTabWidget(), name);
|
---|
| 46 | tab = new TabWidget(main_tab->NewRow(), name);
|
---|
| 47 | sensor_tab = new Tab(tab, "Setup");
|
---|
| 48 | setup_groupbox = new GroupBox(sensor_tab->NewRow(), name);
|
---|
| 49 | setup_layout = new GridLayout(sensor_tab->NewRow(), "setup");
|
---|
[3] | 50 | }
|
---|
| 51 |
|
---|
[15] | 52 | Camera::Camera(const IODevice *parent, std::string name)
|
---|
| 53 | : IODevice(parent, name) {
|
---|
| 54 | plot_tab = NULL;
|
---|
| 55 | main_tab = NULL;
|
---|
| 56 | tab = NULL;
|
---|
| 57 | sensor_tab = NULL;
|
---|
| 58 | setup_groupbox = NULL;
|
---|
[3] | 59 |
|
---|
[15] | 60 | output = NULL;
|
---|
[3] | 61 | }
|
---|
| 62 |
|
---|
| 63 | Camera::~Camera() {
|
---|
[15] | 64 | if (main_tab != NULL)
|
---|
| 65 | delete main_tab;
|
---|
[3] | 66 | }
|
---|
| 67 |
|
---|
| 68 | DataType const &Camera::GetOutputDataType() const {
|
---|
[15] | 69 | return output->GetDataType();
|
---|
[3] | 70 | }
|
---|
| 71 |
|
---|
[15] | 72 | GroupBox *Camera::GetGroupBox(void) const { return setup_groupbox; }
|
---|
[3] | 73 |
|
---|
[15] | 74 | GridLayout *Camera::GetLayout(void) const { return setup_layout; }
|
---|
[3] | 75 |
|
---|
| 76 | void Camera::UseDefaultPlot(const core::cvimage *image) {
|
---|
[15] | 77 | if (tab == NULL) {
|
---|
| 78 | Err("not applicable for simulation part.\n");
|
---|
| 79 | return;
|
---|
| 80 | }
|
---|
[3] | 81 |
|
---|
[15] | 82 | plot_tab = new Tab(tab, "Picture");
|
---|
| 83 | Picture *plot = new Picture(plot_tab->NewRow(), ObjectName(), image);
|
---|
[3] | 84 | }
|
---|
| 85 |
|
---|
[15] | 86 | Tab *Camera::GetPlotTab(void) const { return plot_tab; }
|
---|
[3] | 87 |
|
---|
[15] | 88 | uint16_t Camera::Width(void) const { return output->GetDataType().GetWidth(); }
|
---|
[3] | 89 |
|
---|
| 90 | uint16_t Camera::Height(void) const {
|
---|
[15] | 91 | return output->GetDataType().GetHeight();
|
---|
[3] | 92 | }
|
---|
| 93 |
|
---|
[15] | 94 | core::cvimage *Camera::Output(void) { return output; }
|
---|
[3] | 95 |
|
---|
| 96 | void Camera::SaveToFile(string filename) const {
|
---|
[15] | 97 | Printf("saving %s, size %i\n", filename.c_str(), output->img->imageSize);
|
---|
| 98 | std::ofstream pFile;
|
---|
| 99 | pFile.open(filename);
|
---|
| 100 | output->GetMutex();
|
---|
| 101 | pFile.write(output->img->imageData, output->img->imageSize);
|
---|
| 102 | output->ReleaseMutex();
|
---|
[3] | 103 |
|
---|
[15] | 104 | pFile.close();
|
---|
[3] | 105 | }
|
---|
| 106 |
|
---|
| 107 | } // end namespace sensor
|
---|
| 108 | } // end namespace flair
|
---|