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 */
25
27
28#include <opencv2/imgproc/imgproc.hpp>
29
32
33#include <Calibration/Calibration.h>
34
35namespace visionx
36{
37
41
42
44} // namespace visionx
45
46 std::string
48 {
49 return "VideoFileImageProvider";
50 }
51
52 std::string
57
58void
60{
61 ARMARX_INFO << "Opening video file " << getProperty<std::string>("VideoFilePath").getValue();
62
63 if (!openVideo())
64 {
65 throw armarx::LocalException("Failed to open Videofile ")
66 << getProperty<std::string>("VideoFilePath").getValue();
67 }
69 this->frameRate = capturer.get(cv::CAP_PROP_FPS);
70 ARMARX_INFO << "Video Size: " << capturer.get(cv::CAP_PROP_FRAME_WIDTH) << "x"
71 << capturer.get(cv::CAP_PROP_FRAME_HEIGHT);
72 setImageFormat(ImageDimension(capturer.get(cv::CAP_PROP_FRAME_WIDTH),
73 capturer.get(cv::CAP_PROP_FRAME_HEIGHT)),
74 visionx::eRgb,
75 visionx::eBayerPatternGr);
76 setImageSyncMode(visionx::eFpsSynchronization);
77}
78
79void
84
85bool
87{
88 // TIMING_START(capture);
89 auto result = capturer.read(image);
90 if (!result && capturer.isOpened() && getProperty<bool>("LoopVideo").getValue())
91 {
92 capturer.release();
93 openVideo();
94 result = capturer.read(image);
95 }
96 // TIMING_END(capture);
97 if (result && sharedMemoryProvider)
98 {
99 Ice::Byte* pixels = static_cast<Ice::Byte*>(image.data);
100 // TIMING_START(conversion);
101
102 cv::cvtColor(image, image, cv::COLOR_RGB2BGR);
103 // TIMING_END(conversion);
104 // TIMING_START(mutex);
106 // TIMING_END(mutex);
107 // TIMING_START(copy);
108 memcpy(ppImageBuffers[0], pixels, image.cols * image.rows * image.channels());
109 // TIMING_END(copy);
110 }
111
112 // TIMING_END(capture);
113 return result;
114}
115
116bool
118{
119 auto result = capturer.open(getProperty<std::string>("VideoFilePath").getValue());
120 // CCalibration::LoadCameraParameters();
121 return result;
122}
123
124void
126{
127 ARMARX_INFO << __FUNCTION__;
128 // capturer.set(CV_CAP_PROP_FPS, framesPerSecond);
129}
130
131void
135
142
143visionx::MonocularCalibration
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
Throw this exception to indicate missing functionality.
void setImageSyncMode(ImageSyncMode imageSyncMode)
Sets the image synchronization mode.
armarx::IceSharedMemoryProvider< unsignedchar >::pointer_type sharedMemoryProvider
shared memory provider
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
void setNumberImages(int numberImages)
Sets the number of images on each capture.
MonocularCalibration getCalibration(const Ice::Current &)
void onStartCapture(float framesPerSecond) override
This is called when the image provider capturing has been started.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onStopCapture() override
This is called when the image provider capturing has been stopped.
void onExitCapturingImageProvider() override
This is called when the Component::onExitComponent() setup is called.
void onInitCapturingImageProvider() override
This is called when the Component::onInitComponent() is called.
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.