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
26#include <opencv2/imgproc/imgproc.hpp>
27
30
31#include <Calibration/Calibration.h>
32
33namespace visionx
34{
35
39
40} // namespace visionx
41
42std::string
44{
45 return "VideoFileImageProvider";
46}
47
48void
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 }
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
69void
74
75bool
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);
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
106bool
108{
109 auto result = capturer.open(getProperty<std::string>("VideoFilePath").getValue());
110 // CCalibration::LoadCameraParameters();
111 return result;
112}
113
114void
116{
117 ARMARX_INFO << __FUNCTION__;
118 // capturer.set(CV_CAP_PROP_FPS, framesPerSecond);
119}
120
121void
125
132
133visionx::MonocularCalibration
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.