X11ScreenCaptureImageProvider.cpp
Go to the documentation of this file.
2
4
6
7namespace visionx
8{
9
10 const std::string X11ScreenCaptureImageProvider::defaultName = "X11ScreenCapture";
11
13 {
14 clock = armarx::Clock(armarx::ClockType::Realtime);
15 }
16
17 std::string
19 {
20 return defaultName;
21 }
22
23 std::string
28
29 void
31 {
32 ARMARX_INFO << "Initializing X11...";
33
34 display = XOpenDisplay(nullptr);
35
36 ARMARX_CHECK_GREATER_EQUAL(properties.screenNumber, 0);
37 ARMARX_CHECK_LESS(properties.screenNumber, XScreenCount(display));
38 window = RootWindow(display, properties.screenNumber);
39
41
42 // setImageFormat(ImageDimension(dim.width, dim.height), visionx::eRgb, visionx::eBayerPatternGr);
43 setImageFormat(ImageDimension(properties.width, properties.height),
44 visionx::eRgb,
45 visionx::eBayerPatternGr);
46
47 out = cv::Mat(properties.height, properties.width, CV_8UC3);
48
49 setImageSyncMode(visionx::eFpsSynchronization);
50 frameRate = properties.fps;
51 ARMARX_INFO << "Using " << frameRate << " FPS";
52 }
53
54 void
56 {
57 if (ximg != nullptr)
58 {
59 XDestroyImage(ximg);
60 }
61
62 XCloseDisplay(display);
63 }
64
65 bool
67 {
68 if (ximg != nullptr)
69 {
70 XDestroyImage(ximg);
71 }
72
73 ximg = XGetImage(display,
74 window,
75 properties.x,
76 properties.y,
77 properties.width,
78 properties.height,
79 AllPlanes,
80 ZPixmap);
81 ximg_cv = cv::Mat(properties.height, properties.width, CV_8UC4, ximg->data);
82
83 auto tmpSharedMemoryProvider = sharedMemoryProvider;
84 if (tmpSharedMemoryProvider)
85 {
86 Ice::Byte* pixels = static_cast<Ice::Byte*>(out.data);
87 updateTimestamp(clock.now().toMicroSecondsSinceEpoch());
88 cv::cvtColor(ximg_cv, out, cv::COLOR_RGBA2BGR);
90 tmpSharedMemoryProvider->getScopedWriteLock());
91 memcpy(ppImageBuffers[0], pixels, out.cols * out.rows * out.channels());
92 }
93
94 return true;
95 }
96
97 void
99 {
100 properties.fps = static_cast<int>(framesPerSecond);
101 }
102
103 void
108
111 {
114
115 defs->optional(properties.screenNumber,
116 "screen.number",
117 "Screen number to record. This does not correspond to "
118 "the monitor count, as this is transparent to X. You "
119 "don't want to change this in most cases.");
120 defs->optional(properties.fps, "fps", "Frames per second.");
121 defs->optional(properties.x, "region.x", "X coordinate of the region to record.");
122 defs->optional(properties.y, "region.y", "Y coordinate of the region to record.");
123 defs->optional(properties.width, "region.width", "Width of the region to record.");
124 defs->optional(properties.height, "region.height", "Height of the region to record.");
125
126 return defs;
127 }
128
129 std::vector<imrec::ChannelPreferences>
131 {
133
134 imrec::ChannelPreferences cp;
135 cp.requiresLossless = false;
136 cp.name = "screen";
137 return {cp};
138 }
139} // namespace visionx
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Clock to get date/time from a specific clock type or wait for certain durations or until certain date...
Definition Clock.h:26
void setImageSyncMode(ImageSyncMode imageSyncMode)
Sets the image synchronization mode.
armarx::IceSharedMemoryProvider< unsignedchar >::pointer_type sharedMemoryProvider
shared memory provider
void updateTimestamp(Ice::Long timestamp, bool threadSafe=true)
Updates the timestamp of the currently captured image.
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.
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.
std::vector< imrec::ChannelPreferences > getImageRecordingChannelPreferences(const Ice::Current &) override
void onInitCapturingImageProvider() override
This is called when the Component::onInitComponent() is called.
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_CHECK_LESS(lhs, rhs)
This macro evaluates whether lhs is less (<) than rhs and if it turns out to be false it will throw a...
#define ARMARX_CHECK_GREATER_EQUAL(lhs, rhs)
This macro evaluates whether lhs is greater or equal (>=) rhs and if it turns out to be false it will...
#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.
#define ARMARX_TRACE
Definition trace.h:77