VideoFileImageProvider.cpp
Go to the documentation of this file.
1 #/*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2017, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2017
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "VideoFileImageProvider.h"
25 
26 #include <opencv2/imgproc/imgproc.hpp>
27 
30 
31 #include <Calibration/Calibration.h>
32 
33 namespace visionx
34 {
35 
37  {
38  }
39 
40 } // namespace visionx
41 
42 std::string
44 {
45  return "VideoFileImageProvider";
46 }
47 
48 void
50 {
51  ARMARX_INFO << "Opening video file " << getProperty<std::string>("VideoFilePath").getValue();
52 
53  if (!openVideo())
54  {
55  throw armarx::LocalException("Failed to open Videofile ")
56  << getProperty<std::string>("VideoFilePath").getValue();
57  }
58  setNumberImages(1);
59  this->frameRate = capturer.get(cv::CAP_PROP_FPS);
60  ARMARX_INFO << "Video Size: " << capturer.get(cv::CAP_PROP_FRAME_WIDTH) << "x"
61  << capturer.get(cv::CAP_PROP_FRAME_HEIGHT);
62  setImageFormat(ImageDimension(capturer.get(cv::CAP_PROP_FRAME_WIDTH),
63  capturer.get(cv::CAP_PROP_FRAME_HEIGHT)),
64  visionx::eRgb,
65  visionx::eBayerPatternGr);
66  setImageSyncMode(visionx::eFpsSynchronization);
67 }
68 
69 void
71 {
72  capturer.release();
73 }
74 
75 bool
77 {
78  // TIMING_START(capture);
79  auto result = capturer.read(image);
80  if (!result && capturer.isOpened() && getProperty<bool>("LoopVideo").getValue())
81  {
82  capturer.release();
83  openVideo();
84  result = capturer.read(image);
85  }
86  // TIMING_END(capture);
87  if (result && sharedMemoryProvider)
88  {
89  Ice::Byte* pixels = static_cast<Ice::Byte*>(image.data);
90  // TIMING_START(conversion);
91 
92  cv::cvtColor(image, image, cv::COLOR_RGB2BGR);
93  // TIMING_END(conversion);
94  // TIMING_START(mutex);
95  armarx::SharedMemoryScopedWriteLockPtr lock(sharedMemoryProvider->getScopedWriteLock());
96  // TIMING_END(mutex);
97  // TIMING_START(copy);
98  memcpy(ppImageBuffers[0], pixels, image.cols * image.rows * image.channels());
99  // TIMING_END(copy);
100  }
101 
102  // TIMING_END(capture);
103  return result;
104 }
105 
106 bool
108 {
109  auto result = capturer.open(getProperty<std::string>("VideoFilePath").getValue());
110  // CCalibration::LoadCameraParameters();
111  return result;
112 }
113 
114 void
116 {
117  ARMARX_INFO << __FUNCTION__;
118  // capturer.set(CV_CAP_PROP_FPS, framesPerSecond);
119 }
120 
121 void
123 {
124 }
125 
128 {
130  new VideoFileImageProviderPropertyDefinitions(getConfigIdentifier()));
131 }
132 
133 visionx::MonocularCalibration
135 {
137 }
visionx::VideoFileImageProvider::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: VideoFileImageProvider.cpp:70
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::VideoFileImageProvider::onInitCapturingImageProvider
void onInitCapturingImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: VideoFileImageProvider.cpp:49
visionx::VideoFileImageProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: VideoFileImageProvider.cpp:127
visionx::VideoFileImageProvider::openVideo
bool openVideo()
Definition: VideoFileImageProvider.cpp:107
visionx::VideoFileImageProvider::VideoFileImageProvider
VideoFileImageProvider()
Definition: VideoFileImageProvider.cpp:36
armarx::SharedMemoryScopedWriteLockPtr
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
Definition: SharedMemoryProvider.h:47
visionx::VideoFileImageProviderPropertyDefinitions
Definition: VideoFileImageProvider.h:33
visionx::VideoFileImageProvider::getCalibration
MonocularCalibration getCalibration(const Ice::Current &)
Definition: VideoFileImageProvider.cpp:134
visionx::VideoFileImageProvider::onStartCapture
void onStartCapture(float framesPerSecond) override
This is called when the image provider capturing has been started.
Definition: VideoFileImageProvider.cpp:115
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:109
NotImplementedYetException.h
visionx::VideoFileImageProvider::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: VideoFileImageProvider.cpp:43
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::exceptions::user::NotImplementedYetException
Throw this exception to indicate missing functionality.
Definition: NotImplementedYetException.h:39
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
VideoFileImageProvider.h
visionx::VideoFileImageProvider::onStopCapture
void onStopCapture() override
This is called when the image provider capturing has been stopped.
Definition: VideoFileImageProvider.cpp:122