Added param -http_port 8090 to show MJPEG-stream in the WebBrowser (Chrome/Firefox)
9 files modified
4 files added
| | |
| | | LDFLAGS+= -L/usr/local/cudnn/lib64 -lcudnn |
| | | endif |
| | | |
| | | OBJ=gemm.o utils.o cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o super.o voxel.o tree.o |
| | | OBJ=http_stream.o gemm.o utils.o cuda.o convolutional_layer.o list.o image.o activations.o im2col.o col2im.o blas.o crop_layer.o dropout_layer.o maxpool_layer.o softmax_layer.o data.o matrix.o network.o connected_layer.o cost_layer.o parser.o option_list.o darknet.o detection_layer.o captcha.o route_layer.o writing.o box.o nightmare.o normalization_layer.o avgpool_layer.o coco.o dice.o yolo.o detector.o layer.o compare.o classifier.o local_layer.o swag.o shortcut_layer.o activation_layer.o rnn_layer.o gru_layer.o rnn.o rnn_vid.o crnn_layer.o demo.o tag.o cifar.o go.o batchnorm_layer.o art.o region_layer.o reorg_layer.o super.o voxel.o tree.o |
| | | ifeq ($(GPU), 1) |
| | | LDFLAGS+= -lstdc++ |
| | | OBJ+=convolutional_kernels.o activation_kernels.o im2col_kernels.o col2im_kernels.o blas_kernels.o crop_layer_kernels.o dropout_layer_kernels.o maxpool_layer_kernels.o network_kernels.o avgpool_layer_kernels.o |
| | |
| | | endif |
| | | |
| | | $(EXEC): $(OBJS) |
| | | $(CC) $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS) |
| | | $(CPP) $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS) |
| | | |
| | | $(OBJDIR)%.o: %.c $(DEPS) |
| | | $(CC) $(COMMON) $(CFLAGS) -c $< -o $@ |
| | | |
| | | $(OBJDIR)%.o: %.cpp $(DEPS) |
| | | $(CPP) $(COMMON) $(CFLAGS) -c $< -o $@ |
| | | |
| | | $(OBJDIR)%.o: %.cu $(DEPS) |
| | | $(NVCC) $(ARCH) $(COMMON) --compiler-options "$(CFLAGS)" -c $< -o $@ |
| | | |
| | |
| | | <ClCompile Include="..\..\src\gettimeofday.c" /> |
| | | <ClCompile Include="..\..\src\go.c" /> |
| | | <ClCompile Include="..\..\src\gru_layer.c" /> |
| | | <ClCompile Include="..\..\src\http_stream.cpp" /> |
| | | <ClCompile Include="..\..\src\im2col.c" /> |
| | | <ClCompile Include="..\..\src\image.c" /> |
| | | <ClCompile Include="..\..\src\layer.c" /> |
| | |
| | | <ClInclude Include="..\..\src\getopt.h" /> |
| | | <ClInclude Include="..\..\src\gettimeofday.h" /> |
| | | <ClInclude Include="..\..\src\gru_layer.h" /> |
| | | <ClInclude Include="..\..\src\http_stream.h" /> |
| | | <ClInclude Include="..\..\src\im2col.h" /> |
| | | <ClInclude Include="..\..\src\image.h" /> |
| | | <ClInclude Include="..\..\src\layer.h" /> |
| New file |
| | |
| | | rem Run this file and then open URL in Chrome/Firefox: rem http://localhost:8090 |
| | | rem Or open: http://ip-address:8090 |
| | | |
| | | darknet.exe detector demo data/voc.data yolo-voc.cfg yolo-voc.weights test.mp4 -i 0 -http_port 8090 |
| | | |
| | | |
| | | pause |
| | |
| | | <ClCompile Include="..\..\src\gettimeofday.c" /> |
| | | <ClCompile Include="..\..\src\go.c" /> |
| | | <ClCompile Include="..\..\src\gru_layer.c" /> |
| | | <ClCompile Include="..\..\src\http_stream.cpp" /> |
| | | <ClCompile Include="..\..\src\im2col.c" /> |
| | | <ClCompile Include="..\..\src\image.c" /> |
| | | <ClCompile Include="..\..\src\layer.c" /> |
| | |
| | | <ClInclude Include="..\..\src\getopt.h" /> |
| | | <ClInclude Include="..\..\src\gettimeofday.h" /> |
| | | <ClInclude Include="..\..\src\gru_layer.h" /> |
| | | <ClInclude Include="..\..\src\http_stream.h" /> |
| | | <ClInclude Include="..\..\src\im2col.h" /> |
| | | <ClInclude Include="..\..\src\image.h" /> |
| | | <ClInclude Include="..\..\src\layer.h" /> |
| New file |
| | |
| | | rem Run this file and then open URL in Chrome/Firefox: rem http://localhost:8090 |
| | | rem Or open: http://ip-address:8090 |
| | | |
| | | ./darknet detector demo ./cfg/voc.data ./cfg/yolo-voc.cfg ./yolo-voc.weights test50.mp4 -i 0 -thresh 0.2 -http_port 8090 |
| | | |
| | | |
| | | |
| | | pause |
| | |
| | | |
| | | void run_coco(int argc, char **argv) |
| | | { |
| | | int http_stream_port = find_int_arg(argc, argv, "-http_port", -1); |
| | | char *out_filename = find_char_arg(argc, argv, "-out_filename", 0); |
| | | char *prefix = find_char_arg(argc, argv, "-prefix", 0); |
| | | float thresh = find_float_arg(argc, argv, "-thresh", .2); |
| | |
| | | else if(0==strcmp(argv[2], "train")) train_coco(cfg, weights); |
| | | else if(0==strcmp(argv[2], "valid")) validate_coco(cfg, weights); |
| | | else if(0==strcmp(argv[2], "recall")) validate_coco_recall(cfg, weights); |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, coco_classes, 80, frame_skip, prefix, out_filename); |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, coco_classes, 80, frame_skip, |
| | | prefix, out_filename, http_stream_port); |
| | | } |
| | |
| | | static float *avg; |
| | | |
| | | void draw_detections_cv(IplImage* show_img, int num, float thresh, box *boxes, float **probs, char **names, image **alphabet, int classes); |
| | | void show_image_cv_ipl(IplImage *disp, const char *name, const char *out_filename, int http_stream_port); |
| | | image get_image_from_stream_resize(CvCapture *cap, int w, int h, IplImage** in_img); |
| | | IplImage* in_img; |
| | | IplImage* det_img; |
| | |
| | | return (double)time.tv_sec + (double)time.tv_usec * .000001; |
| | | } |
| | | |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, char *out_filename) |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, |
| | | int frame_skip, char *prefix, char *out_filename, int http_stream_port) |
| | | { |
| | | //skip = frame_skip; |
| | | image **alphabet = load_alphabet(); |
| | |
| | | |
| | | if(!prefix){ |
| | | //show_image(disp, "Demo"); |
| | | show_image_cv_ipl(show_img, "Demo", out_filename); |
| | | show_image_cv_ipl(show_img, "Demo", out_filename, http_stream_port); |
| | | int c = cvWaitKey(1); |
| | | if (c == 10){ |
| | | if(frame_skip == 0) frame_skip = 60; |
| | |
| | | } |
| | | } |
| | | #else |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, char *out_filename) |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, char *out_filename, int http_stream_port) |
| | | { |
| | | fprintf(stderr, "Demo needs OpenCV for webcam images.\n"); |
| | | } |
| | |
| | | #define DEMO |
| | | |
| | | #include "image.h" |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, char *out_filename); |
| | | void demo(char *cfgfile, char *weightfile, float thresh, int cam_index, const char *filename, char **names, int classes, int frame_skip, char *prefix, char *out_filename, int http_stream_port); |
| | | |
| | | #endif |
| | |
| | | |
| | | void run_detector(int argc, char **argv) |
| | | { |
| | | int http_stream_port = find_int_arg(argc, argv, "-http_port", -1); |
| | | char *out_filename = find_char_arg(argc, argv, "-out_filename", 0); |
| | | char *prefix = find_char_arg(argc, argv, "-prefix", 0); |
| | | float thresh = find_float_arg(argc, argv, "-thresh", .24); |
| | |
| | | char **names = get_labels(name_list); |
| | | if(filename) |
| | | if (filename[strlen(filename) - 1] == 0x0d) filename[strlen(filename) - 1] = 0; |
| | | demo(cfg, weights, thresh, cam_index, filename, names, classes, frame_skip, prefix, out_filename); |
| | | demo(cfg, weights, thresh, cam_index, filename, names, classes, frame_skip, prefix, out_filename, http_stream_port); |
| | | } |
| | | } |
| New file |
| | |
| | | #ifdef OPENCV |
| | | // |
| | | // a single-threaded, multi client(using select), debug webserver - streaming out mjpg. |
| | | // on win, _WIN32 has to be defined, must link against ws2_32.lib (socks on linux are for free) |
| | | // |
| | | |
| | | // |
| | | // socket related abstractions: |
| | | // |
| | | #ifdef _WIN32 |
| | | #pragma comment(lib, "ws2_32.lib") |
| | | #include <winsock.h> |
| | | #include <windows.h> |
| | | #include <time.h> |
| | | #define PORT unsigned long |
| | | #define ADDRPOINTER int* |
| | | struct _INIT_W32DATA |
| | | { |
| | | WSADATA w; |
| | | _INIT_W32DATA() { WSAStartup(MAKEWORD(2, 1), &w); } |
| | | } _init_once; |
| | | #else /* ! win32 */ |
| | | #include <unistd.h> |
| | | #include <sys/time.h> |
| | | #include <sys/types.h> |
| | | #include <sys/socket.h> |
| | | #include <netdb.h> |
| | | #include <netinet/in.h> |
| | | #include <arpa/inet.h> |
| | | #define PORT unsigned short |
| | | #define SOCKET int |
| | | #define HOSTENT struct hostent |
| | | #define SOCKADDR struct sockaddr |
| | | #define SOCKADDR_IN struct sockaddr_in |
| | | #define ADDRPOINTER unsigned int* |
| | | #define INVALID_SOCKET -1 |
| | | #define SOCKET_ERROR -1 |
| | | #endif /* _WIN32 */ |
| | | |
| | | #include <vector> |
| | | #include <iostream> |
| | | using std::cerr; |
| | | using std::endl; |
| | | |
| | | #include "opencv2/opencv.hpp" |
| | | using namespace cv; |
| | | |
| | | #include "http_stream.h" |
| | | |
| | | |
| | | class MJPGWriter |
| | | { |
| | | SOCKET sock; |
| | | SOCKET maxfd; |
| | | fd_set master; |
| | | int timeout; // master sock timeout, shutdown after timeout millis. |
| | | int quality; // jpeg compression [1..100] |
| | | |
| | | int _write(int sock, char *s, int len) |
| | | { |
| | | if (len < 1) { len = strlen(s); } |
| | | return ::send(sock, s, len, 0); |
| | | } |
| | | |
| | | public: |
| | | |
| | | MJPGWriter(int port = 0, int _timeout = 200000, int _quality = 30) |
| | | : sock(INVALID_SOCKET) |
| | | , timeout(_timeout) |
| | | , quality(_quality) |
| | | { |
| | | FD_ZERO(&master); |
| | | if (port) |
| | | open(port); |
| | | } |
| | | |
| | | ~MJPGWriter() |
| | | { |
| | | release(); |
| | | } |
| | | |
| | | bool release() |
| | | { |
| | | if (sock != INVALID_SOCKET) |
| | | ::shutdown(sock, 2); |
| | | sock = (INVALID_SOCKET); |
| | | return false; |
| | | } |
| | | |
| | | bool open(int port) |
| | | { |
| | | sock = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| | | |
| | | SOCKADDR_IN address; |
| | | address.sin_addr.s_addr = INADDR_ANY; |
| | | address.sin_family = AF_INET; |
| | | address.sin_port = htons(port); // ::htons(port); |
| | | if (::bind(sock, (SOCKADDR*)&address, sizeof(SOCKADDR_IN)) == SOCKET_ERROR) |
| | | { |
| | | cerr << "error : couldn't bind sock " << sock << " to port " << port << "!" << endl; |
| | | return release(); |
| | | } |
| | | if (::listen(sock, 10) == SOCKET_ERROR) |
| | | { |
| | | cerr << "error : couldn't listen on sock " << sock << " on port " << port << " !" << endl; |
| | | return release(); |
| | | } |
| | | FD_ZERO(&master); |
| | | FD_SET(sock, &master); |
| | | maxfd = sock; |
| | | return true; |
| | | } |
| | | |
| | | bool isOpened() |
| | | { |
| | | return sock != INVALID_SOCKET; |
| | | } |
| | | |
| | | bool write(const Mat & frame) |
| | | { |
| | | fd_set rread = master; |
| | | struct timeval to = { 0,timeout }; |
| | | if (::select(maxfd+1, &rread, NULL, NULL, &to) <= 0) |
| | | return true; // nothing broken, there's just noone listening |
| | | |
| | | std::vector<uchar> outbuf; |
| | | std::vector<int> params; |
| | | params.push_back(IMWRITE_JPEG_QUALITY); |
| | | params.push_back(quality); |
| | | cv::imencode(".jpg", frame, outbuf, params); |
| | | unsigned int outlen = outbuf.size(); |
| | | |
| | | #ifdef _WIN32 |
| | | for (unsigned i = 0; i<rread.fd_count; i++) |
| | | { |
| | | int addrlen = sizeof(SOCKADDR); |
| | | SOCKET s = rread.fd_array[i]; // fd_set on win is an array, while ... |
| | | #else |
| | | for (int s = 0; s<=maxfd; s++) |
| | | { |
| | | socklen_t addrlen = sizeof(SOCKADDR); |
| | | if (!FD_ISSET(s, &rread)) // ... on linux it's a bitmask ;) |
| | | continue; |
| | | #endif |
| | | if (s == sock) // request on master socket, accept and send main header. |
| | | { |
| | | SOCKADDR_IN address = { 0 }; |
| | | SOCKET client = ::accept(sock, (SOCKADDR*)&address, &addrlen); |
| | | if (client == SOCKET_ERROR) |
| | | { |
| | | cerr << "error : couldn't accept connection on sock " << sock << " !" << endl; |
| | | return false; |
| | | } |
| | | maxfd = (maxfd>client ? maxfd : client); |
| | | FD_SET(client, &master); |
| | | _write(client, "HTTP/1.0 200 OK\r\n", 0); |
| | | _write(client, |
| | | "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); |
| | | cerr << "new client " << client << endl; |
| | | } |
| | | else // existing client, just stream pix |
| | | { |
| | | char head[400]; |
| | | sprintf(head, "--mjpegstream\r\nContent-Type: image/jpeg\r\nContent-Length: %lu\r\n\r\n", outlen); |
| | | _write(s, head, 0); |
| | | int n = _write(s, (char*)(&outbuf[0]), outlen); |
| | | //cerr << "known client " << s << " " << n << endl; |
| | | if (n < outlen) |
| | | { |
| | | cerr << "kill client " << s << endl; |
| | | ::shutdown(s, 2); |
| | | FD_CLR(s, &master); |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | }; |
| | | |
| | | |
| | | |
| | | void send_mjpeg(IplImage* ipl, int port, int timeout, int quality) { |
| | | static MJPGWriter wri(port, timeout, quality); |
| | | cv::Mat mat = cv::cvarrToMat(ipl); |
| | | wri.write(mat); |
| | | std::cout << " MJPEG-stream sent. \n"; |
| | | } |
| | | |
| | | #endif // OPENCV |
| New file |
| | |
| | | #pragma once |
| | | #ifndef HTTP_STREAM_H |
| | | #define HTTP_STREAM_H |
| | | |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | | #endif |
| | | |
| | | void send_mjpeg(IplImage* ipl, int port, int timeout, int quality); |
| | | |
| | | #ifdef __cplusplus |
| | | } |
| | | #endif |
| | | |
| | | #endif // HTTP_STREAM_H |
| | |
| | | #include "opencv2/highgui/highgui_c.h" |
| | | #include "opencv2/imgproc/imgproc_c.h" |
| | | #include "opencv2/core/version.hpp" |
| | | #include "http_stream.h" |
| | | #ifndef CV_VERSION_EPOCH |
| | | #include "opencv2/videoio/videoio_c.h" |
| | | #include "opencv2/imgcodecs/imgcodecs_c.h" |
| | | #include "http_stream.h" |
| | | #endif |
| | | #endif |
| | | |
| | | |
| | | int windows = 0; |
| | | |
| | | float colors[6][3] = { {1,0,1}, {0,0,1},{0,1,1},{0,1,0},{1,1,0},{1,0,0} }; |
| | |
| | | } |
| | | |
| | | |
| | | void show_image_cv_ipl(IplImage *disp, const char *name, const char *out_filename) |
| | | void show_image_cv_ipl(IplImage *disp, const char *name, const char *out_filename, int http_stream_port) |
| | | { |
| | | if (disp == NULL) return; |
| | | char buff[256]; |
| | |
| | | ++windows; |
| | | cvShowImage(buff, disp); |
| | | |
| | | |
| | | // http mjpeg stream: http://localhost:8090 |
| | | // use URL with the port number stated in your command line instead of 8090 |
| | | if (http_stream_port > 0) { |
| | | //int port = 8090; |
| | | int port = http_stream_port; |
| | | int timeout = 200; |
| | | int jpeg_quality = 30; // 1 - 100 |
| | | send_mjpeg(disp, port, timeout, jpeg_quality); |
| | | } |
| | | |
| | | |
| | | if(out_filename) |
| | | { |
| | | CvSize size; |
| | |
| | | |
| | | void run_yolo(int argc, char **argv) |
| | | { |
| | | int http_stream_port = find_int_arg(argc, argv, "-http_port", -1); |
| | | char *out_filename = find_char_arg(argc, argv, "-out_filename", 0); |
| | | char *prefix = find_char_arg(argc, argv, "-prefix", 0); |
| | | float thresh = find_float_arg(argc, argv, "-thresh", .2); |
| | |
| | | else if(0==strcmp(argv[2], "train")) train_yolo(cfg, weights); |
| | | else if(0==strcmp(argv[2], "valid")) validate_yolo(cfg, weights); |
| | | else if(0==strcmp(argv[2], "recall")) validate_yolo_recall(cfg, weights); |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, voc_names, 20, frame_skip, prefix, out_filename); |
| | | else if(0==strcmp(argv[2], "demo")) demo(cfg, weights, thresh, cam_index, filename, voc_names, 20, frame_skip, |
| | | prefix, out_filename, http_stream_port); |
| | | } |