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 #include <opencv2/imgproc/imgproc.hpp>
27 #include <Calibration/Calibration.h>
29 namespace visionx
30 {
31 
33  {
34 
35  }
36 
37 } // namespace visionx
38 
39 
41 {
42  return "VideoFileImageProvider";
43 }
44 
45 
46 
48 {
49  ARMARX_INFO << "Opening video file " << getProperty<std::string>("VideoFilePath").getValue();
50 
51  if (!openVideo())
52  {
53  throw armarx::LocalException("Failed to open Videofile ") << getProperty<std::string>("VideoFilePath").getValue();
54  }
55  setNumberImages(1);
56  this->frameRate = capturer.get(cv::CAP_PROP_FPS);
57  ARMARX_INFO << "Video Size: " << capturer.get(cv::CAP_PROP_FRAME_WIDTH) << "x" << capturer.get(cv::CAP_PROP_FRAME_HEIGHT);
58  setImageFormat(ImageDimension(capturer.get(cv::CAP_PROP_FRAME_WIDTH), capturer.get(cv::CAP_PROP_FRAME_HEIGHT)), visionx::eRgb, visionx::eBayerPatternGr);
59  setImageSyncMode(visionx::eFpsSynchronization);
60 }
61 
63 {
64  capturer.release();
65 
66 }
67 
68 bool visionx::VideoFileImageProvider::capture(void** ppImageBuffers)
69 {
70  // TIMING_START(capture);
71  auto result = capturer.read(image);
72  if (!result && capturer.isOpened() && getProperty<bool>("LoopVideo").getValue())
73  {
74  capturer.release();
75  openVideo();
76  result = capturer.read(image);
77  }
78  // TIMING_END(capture);
79  if (result && sharedMemoryProvider)
80  {
81  Ice::Byte* pixels = static_cast<Ice::Byte*>(image.data);
82  // TIMING_START(conversion);
83 
84  cv::cvtColor(image, image, cv::COLOR_RGB2BGR);
85  // TIMING_END(conversion);
86  // TIMING_START(mutex);
87  armarx::SharedMemoryScopedWriteLockPtr lock(sharedMemoryProvider->getScopedWriteLock());
88  // TIMING_END(mutex);
89  // TIMING_START(copy);
90  memcpy(ppImageBuffers[0], pixels, image.cols * image.rows * image.channels());
91  // TIMING_END(copy);
92 
93  }
94 
95  // TIMING_END(capture);
96  return result;
97 }
98 
100 {
101  auto result = capturer.open(getProperty<std::string>("VideoFilePath").getValue());
102  // CCalibration::LoadCameraParameters();
103  return result;
104 }
105 
106 
107 
108 
110 {
111  ARMARX_INFO << __FUNCTION__;
112  // capturer.set(CV_CAP_PROP_FPS, framesPerSecond);
113 
114 }
115 
117 {
118 }
119 
120 
122 {
124 }
125 
126 
127 visionx::MonocularCalibration visionx::VideoFileImageProvider::getCalibration(const Ice::Current&)
128 {
130 }
visionx::VideoFileImageProvider::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: VideoFileImageProvider.cpp:62
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:47
visionx::VideoFileImageProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: VideoFileImageProvider.cpp:121
visionx::VideoFileImageProvider::openVideo
bool openVideo()
Definition: VideoFileImageProvider.cpp:99
visionx::VideoFileImageProvider::VideoFileImageProvider
VideoFileImageProvider()
Definition: VideoFileImageProvider.cpp:32
armarx::SharedMemoryScopedWriteLockPtr
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
Definition: SharedMemoryProvider.h:46
visionx::VideoFileImageProviderPropertyDefinitions
Definition: VideoFileImageProvider.h:33
visionx::VideoFileImageProvider::getCalibration
MonocularCalibration getCalibration(const Ice::Current &)
Definition: VideoFileImageProvider.cpp:127
visionx::VideoFileImageProvider::onStartCapture
void onStartCapture(float framesPerSecond) override
This is called when the image provider capturing has been started.
Definition: VideoFileImageProvider.cpp:109
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:106
NotImplementedYetException.h
visionx::VideoFileImageProvider::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: VideoFileImageProvider.cpp:40
TimeUtil.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
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:34
VideoFileImageProvider.h
visionx::VideoFileImageProvider::onStopCapture
void onStopCapture() override
This is called when the image provider capturing has been stopped.
Definition: VideoFileImageProvider.cpp:116