intial commit
This commit is contained in:
71
main.cpp
Normal file
71
main.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#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);
|
||||
|
||||
std::cout<<"UVOS webcam sender v0.1\n";
|
||||
|
||||
Webcam webcam(config.device, config.Xres, config.Yres);
|
||||
|
||||
std::stringstream ss;
|
||||
ss<<"nc "<<config.url<<' '<<config.port;
|
||||
|
||||
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))
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (!ferror(netcat))
|
||||
{
|
||||
usleep(100);
|
||||
Image frame = webcam.frame(10);
|
||||
if(!config.overlay.empty())
|
||||
overlayImage(frame, overlay);
|
||||
compressJpegImage(netcat, &frame);
|
||||
fflush(netcat);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user