82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <stdexcept>
|
|
#include <sstream>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <cstdint>
|
|
|
|
#include "image.h"
|
|
#include "jpeg_img.h"
|
|
#include "webcam.h"
|
|
#include "options.h"
|
|
|
|
|
|
void overlayImage(Image& target, Image& tool)
|
|
{
|
|
if( target.size() != tool.size() || target.width != tool.width || target.channels != 3 )
|
|
throw std::runtime_error("Overlay Image needs to be same size as target");
|
|
else
|
|
{
|
|
for(uint32_t i = 0; i < target.size(); i+=3)
|
|
{
|
|
if(tool.data.get()[i] != 0xFF || tool.data.get()[i+1] != 0x00 || tool.data.get()[i+2] != 0xFF)
|
|
{
|
|
target.data.get()[i] = tool.data.get()[i];
|
|
target.data.get()[i+1] = tool.data.get()[i+1];
|
|
target.data.get()[i+2] = tool.data.get()[i+2];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void printUsage()
|
|
{
|
|
std::cout<<"useage:\nvideosender [video device] [ip] [port] [overlay]\n";
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
Config config;
|
|
argp_parse(&argp, argc, argv, 0, 0, &config);
|
|
|
|
bool passthough = config.mjpeg && config.overlay.empty();
|
|
|
|
std::cout<<"UVOS webcam sender v0.1\n";
|
|
|
|
Webcam webcam(config.device, config.Xres, config.Yres, config.mjpeg, passthough);
|
|
|
|
std::stringstream ss;
|
|
ss<<"nc "<<config.url<<' '<<config.port<<'\n';
|
|
|
|
std::cout<<"using "<<ss.str();
|
|
|
|
FILE* netcat = popen(ss.str().c_str(), "w");
|
|
|
|
Image overlay;
|
|
if(!config.overlay.empty())
|
|
{
|
|
if(!overlay.open(config.overlay.c_str(), config.Xres, config.Yres, 3))
|
|
{
|
|
std::cout<<"Unable to open "<<config.overlay<<'\n';
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
while (!ferror(netcat))
|
|
{
|
|
usleep(100);
|
|
Image frame = webcam.frame(10);
|
|
if(!config.overlay.empty())
|
|
overlayImage(frame, overlay);
|
|
if(!passthough)
|
|
compressJpegImage(netcat, &frame);
|
|
else
|
|
fwrite(frame.data.get(), frame.size(), 1, netcat);
|
|
fflush(netcat);
|
|
}
|
|
|
|
return 0;
|
|
}
|