Может ли кто-нибудь помочь мне решить проблему в моем коде? Короче говоря, идея состоит в том, чтобы прочитать веб-камеру /dev/video0, вставить фоновое изображение (jpg, png обои) и отправить его в /dev/video2.
Я использую v4l2loopback .
modprobe v4l2loopback video_nr=2 devices=1 card_label="Виртуальная камера"exclusive_caps=0 Keep_format=1
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
struct Buffer {
void *start;
size_t length;
};
struct CameraInfo {
int width;
int height;
__u32 pixelFormat;
};
std::atomic running{true};
void applyBackground(const cv::Mat &foreground, const cv::Mat &background, cv::Mat &output) {
output = foreground.clone();
for (int i = 0; i < foreground.rows; ++i) {
for (int j = 0; j < foreground.cols; ++j) {
cv::Vec3b pixel = foreground.at(i, j);
cv::Vec3b bgPixel = background.at(i, j);
if (pixel[0] < 50 && pixel[1] < 50 && pixel[2] < 50) {
output.at(i, j) = bgPixel;
} else {
output.at(i, j)[0] = (pixel[0] * 0.7 + bgPixel[0] * 0.3);
output.at(i, j)[1] = (pixel[1] * 0.7 + bgPixel[1] * 0.3);
output.at(i, j)[2] = (pixel[2] * 0.7 + bgPixel[2] * 0.3);
}
}
}
}
cv::Mat loadBackground(const std::string &path, int width, int height) {
cv::Mat bg = cv::imread(path);
if (bg.empty()) {
std::cerr
Подробнее здесь: https://stackoverflow.com/questions/792 ... her-device
Захватите изображение с веб-камеры, поместите фоновое изображение и отправьте его на другое устройство. ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение