jpery / mjpegwriter Goto Github PK
View Code? Open in Web Editor NEWLightweight HTTP server to stream your OpenCV processing in C++
License: MIT License
Lightweight HTTP server to stream your OpenCV processing in C++
License: MIT License
I installed opencv library version 4.5.0-pre on raspberry pi 4.
But I have errors:
/usr/bin/ld: /tmp/ccjurhlf.o: неопределённая ссылка на символ «_ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERSt6vectorIhSaIhEERKSB_IiSaIiEE»
/usr/bin/ld: //usr/local/lib/libopencv_imgcodecs.so.4.5: error adding symbols: в командной строке не указан DSO
collect2: error: ld returned 1 exit status
I solved this problem by replacing CV_ * with cv :: in the file according to this recommendation. Also I used the following command to compile.
sudo g++ MJPEGWriter.cpp main.cpp -o MJPEG -lpthread -lopencv_highgui -lopencv_core -lopencv_imgcodecs -lopencv_videoio -std=c++11
Hello there! I'm download and sucessfully compiled your code. Run "MJPEG" and when I enter the address in the browser (localhost:7777 or 127.0.0.1:7777), the page loads indefinitely and nothing opens. in VLC the same does not work. Maybe I'm doing something wrong, can you tell?
Regards
Hi,
How to compile for windows?
thanks,
Compiling led to a few undefined references under Ubuntu 18.04. The following might be a better way to compile this if you want to stick to pure g++:
g++ MJPEGWriter.cpp main.cpp -o MJPEG -lpthread `pkg-config opencv --cflags --libs` -std=c++11
Dear JPery,
I would like to implement this method in my project, but I am curious whether do I need a HTTP server to have this done?
Thank you
Line 78 in 55c0af8
I believe def's got updated with cv4+ and do not use the CV_
prefix anymore.
great code by the way :)
First I converted my output QImage to Mat and then I write that converted Mat in MJPEGWriter. I observed screen tearing problem.
How can I solve this problem?
Hey, any chance you could add a license to this project? Preferably MIT or something related would be nice.
Thanks!
hi, first thank you for pulling the example together, I've benefited from it a lot as a socket noobie.
When I ran the example, I was having issue stoping the socket thread on both listens & writes. It seems to stuck at p_thread trying to join the writes & listens. Would you kindly provides some insight ? Thank you.
Hi, I'm making Image processing auto-line-tracing vehicle by raspberry-pi.
and, Im beginer of opencv. I tried to find information about that by google, books etc.
Finally , I found your git . Thank you so much.
I toke the code on my vehicle, and this is the picture,
I want the picture rotate 180 angle and remove (some?) color correction filter.
(truly, I also want more resolution)
So please give me the way .... THANK YOU
Could you please add performance/benchmark tests?
I have incorporated this into a C++ design on ARM. I instantiate MJPEGWriter in the class in another classes constructor like this:
mjpgWriter = new MJPEGWriter(8080);
Then to write a new frame I use this code:
mjpgWriter->write(drawing); if(!mjpgWriter->isOpened()) { mjpgWriter->start(); }
Over the course of about a day MJPGWriter goes from consuming very little to all of the system memory (4GB in this case) and crashes.
Any idea why this might be happening?
It works well with vlc player. However chrome only shows first image. Is there any way to test in the browser using img src tag?
i compiled it and i works, great idea and was exactly what i was looking for. I could stream frames coming from hardware to firefox / vlc.
i noticed though that as soon as its started, it takes up a lot of processing time (from looking over the code it seems the load comes from the Writer) which keeps writing even when no client is yet connected / or the last client disconnected
would it not be better if it starts writing only after at least one client is connected (and stops after the last disconnects)?
If no client is connected just Listen and wait until one connects or is there smt that would stand against that?
Is there anyway the stream encoded can be authorised with username and password?
Hi,
I'm trying to use your code to stream mjpg from a c++ application. The code is running and the server is accepting connections, however I can't seem to access the video (either from the browser or VLC).
Could you specify the exact URL of the stream? Sorry if it's a bit basic...
Thanks!
Hi,
I am new to the c++.
how we can put the mjpeg server a std::thread ? so video cap and mjpeg server will be separate thred ?
Best
Hi, I'm compiling for raspbian and the program works but socket "accept" command is returning -1 as soon as it is reached. One hot fix is to move all open() code to Listener() (before loop), maybe there is a problem with sharing resources between threads?
This is my working code:
void
MJPEGWriter::Listener()
{
fd_set rread;
SOCKET maxfd;
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
// SOCKADDR_IN address;
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(port);
if (::bind(sock, (SOCKADDR*)&address, sizeof(address)) == SOCKET_ERROR)
{
cerr << "error : couldn't bind sock " << sock << " to port " << port << "!" << endl;
return;
}
if (listen(sock, NUM_CONNECTIONS) == SOCKET_ERROR)
{
cerr << "error : couldn't listen on sock " << sock << " on port " << port << " !" << endl;
return;
}
cout << "Listening on socket " << sock << " on port " << port << "..." << endl;
FD_SET(sock, &master);
// cout << "Master: " << master << endl;
while (true)
{
rread = master;
struct timeval to = { 0, timeout };
maxfd = sock + 1;
int sel = select(maxfd, &rread, NULL, NULL, &to);
if (sel > 0) {
for (int s = 0; s < maxfd; s++)
{
if (FD_ISSET(s, &rread) && s == sock)
{
sockaddr_in client_addr;
socklen_t client_addr_len = sizeof(client_addr);
// SOCKADDR_IN address = { 0 };
SOCKET client = accept(sock, (struct sockaddr*)&client_addr, &client_addr_len);
if (client == SOCKET_ERROR)
{
cerr << "error : couldn't accept connection on sock " << sock << " !" << endl;
return;
}
maxfd = (maxfd>client ? maxfd : client);
pthread_mutex_lock(&mutex_cout);
cout << "new client " << client << endl;
pthread_mutex_unlock(&mutex_cout);
pthread_mutex_lock(&mutex_client);
_write(client, (char*)"HTTP/1.0 200 OK\r\n", 0);
_write(client, (char*)
"Server: Mozarella/2.2\r\n"
"Accept-Range: bytes\r\n"
"Connection: close\r\n"
"Max-Age: 0\r\n"
"Expires: 0\r\n"
"Cache-Control: no-cache, private\r\n"
"Pragma: no-cache\r\n"
"Content-Type: multipart/x-mixed-replace; boundary=mjpegstream\r\n"
"\r\n", 0);
clients.push_back(client);
pthread_mutex_unlock(&mutex_client);
}
}
}
usleep(1000);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.