25 #include <opencv2/imgproc/imgproc.hpp>
28 #include <Calibration/Calibration.h>
44 return "WebCamImageProvider";
50 std::vector<ImageDimension> supportedVideoResolutions;
51 const ImageDimension CommonResolutions[] =
53 ImageDimension(320, 240),
54 ImageDimension(640, 480),
55 ImageDimension(800, 600),
56 ImageDimension(768, 576),
57 ImageDimension(1024, 768),
58 ImageDimension(1280, 720),
59 ImageDimension(1280, 960),
60 ImageDimension(1280, 1024),
61 ImageDimension(1600, 1200),
62 ImageDimension(1920, 1080),
63 ImageDimension(1920, 1200),
64 ImageDimension(2560, 1440),
65 ImageDimension(3849, 2160)
67 int nbTests =
sizeof(CommonResolutions) /
sizeof(CommonResolutions[0]);
69 for (
int i = 0; i < nbTests; i++)
71 ImageDimension test = CommonResolutions[i];
74 camera.set(cv::CAP_PROP_FRAME_WIDTH, test.width);
75 camera.set(cv::CAP_PROP_FRAME_HEIGHT, test.height);
76 camera.set(cv::CAP_PROP_AUTOFOCUS, 0);
78 double width = camera.get(cv::CAP_PROP_FRAME_WIDTH);
79 double height = camera.get(cv::CAP_PROP_FRAME_HEIGHT);
80 if (test.width == width && test.height == height)
82 supportedVideoResolutions.push_back(test);
86 return supportedVideoResolutions;
93 capturer.open(getProperty<int>(
"DeviceNumber").getValue());
97 auto dim = getProperty<ImageDimension>(
"ImageResolution").getValue();
100 auto supportedResolutions = getSupportedResolutions(capturer);
101 ARMARX_INFO <<
"Supported resolutions: " << supportedResolutions;
103 capturer.set(cv::CAP_PROP_FRAME_WIDTH, supportedResolutions.rbegin()->width);
104 capturer.set(cv::CAP_PROP_FRAME_HEIGHT, supportedResolutions.rbegin()->height);
105 ARMARX_INFO <<
"Using max resolution found for camera: " << capturer.get(cv::CAP_PROP_FRAME_WIDTH) <<
"x" << capturer.get(cv::CAP_PROP_FRAME_HEIGHT);
109 capturer.set(cv::CAP_PROP_FRAME_WIDTH, dim.width);
110 capturer.set(cv::CAP_PROP_FRAME_HEIGHT, dim.height);
111 ARMARX_INFO <<
"Using resolution " << capturer.get(cv::CAP_PROP_FRAME_WIDTH) <<
"x" << capturer.get(cv::CAP_PROP_FRAME_HEIGHT);
114 setImageFormat(ImageDimension(capturer.get(cv::CAP_PROP_FRAME_WIDTH), capturer.get(cv::CAP_PROP_FRAME_HEIGHT)), visionx::eRgb, visionx::eBayerPatternGr);
115 if (getProperty<float>(
"FPS").isSet())
117 setImageSyncMode(visionx::eFpsSynchronization);
118 frameRate = getProperty<float>(
"FPS").getValue();
123 setImageSyncMode(visionx::eCaptureSynchronization);
136 auto result = capturer.read(image);
138 auto tmpSharedMemoryProvider = sharedMemoryProvider;
139 if (result && tmpSharedMemoryProvider)
141 Ice::Byte* pixels =
static_cast<Ice::Byte*
>(image.data);
144 cv::cvtColor(image, image, cv::COLOR_RGB2BGR);
150 memcpy(ppImageBuffers[0], pixels, image.cols * image.rows * image.channels());
185 std::vector<imrec::ChannelPreferences>
190 imrec::ChannelPreferences cp;
191 cp.requiresLossless =
false;