GithubHelp home page GithubHelp logo

mesutpiskin / opencv-live-video-stream-over-http Goto Github PK

View Code? Open in Web Editor NEW
52.0 52.0 16.0 27 KB

:satellite: OpenCV is a sample project that is read from the video source (Camera, File System, NVR, DVR etc.) and displays the processed image via the http protocol.

Java 100.00%
http-server image-processing java opencv video-streaming

opencv-live-video-stream-over-http's Introduction

Hi there, I'm Mesut ๐Ÿ‘‹

I'm a software engineer working primarily with backend technologies. I have extensive experience in software development and architecture design, focusing on creating highly available, low latency, reliable, distributed, and secure software architectures. I specialize in solving complex problems efficiently and providing value through rapid development and the release of quality features.

Find me around the web ๐ŸŒŽ

Visit my website ๐ŸŒ

For more information about me, check out mesutpiskin.com.

opencv-live-video-stream-over-http's People

Contributors

mesutpiskin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opencv-live-video-stream-over-http's Issues

How can I send string over http socket ?

I want to send the String contineously over http socket.

   ac  f=new ac();
  String string = f.getSt();

  byte[] byteArray = string.getBytes();

  os.write("HTTP/1.0 200 OK\n".getBytes());
  os.write(new String("Content-Length: " + byteArray.length + "\n").getBytes());
  os.write("Content-Type: text/html\n\n".getBytes());

  os.write(byteArray);

I want to get and send the the String over the socket contineously .

This project get and sent the webcam image over http socket contineously.

But, I want to get and send the the String over the socket contineously .

How can I do this ?

I asked this question because I did't know more about http stream in java.

and I can't understand the following codes

   stream.write(("HTTP/1.0 200 OK\r\n" +
            "Connection: close\r\n" +
            "Max-Age: 0\r\n" +
            "Expires: 0\r\n" +
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" +
            "Pragma: no-cache\r\n" +
            "Content-Type: multipart/x-mixed-replace; " +
            "boundary=" + boundary + "\r\n" +
            "\r\n" +
            "--" + boundary + "\r\n").getBytes());

and this

outputStream.write(("Content-type: image/jpeg\r\n" +
                "Content-Length: " + imageBytes.length + "\r\n" +
                "\r\n").getBytes());

How to read from stream using OpenCV

I want the other way around - I want to read network stream. I have no clue how to read video directly from (any) input stream. Do you know how to do it?

Add JPEG Quality/Compression

@mesutpiskin (moved this issue from the wrong place and corrected it - major change to my thinking)
Thanks for this project. Well done! It's just what I needed for a simple server of a camera frame with an overlay of an OpenCV drawing.

I wanted to control the JPG quality so I gleaned a technique from StackOverflow answers concerning encoding Java Swing types. I had posted that yesterday in the wrong issue but I browsed through your code today and I see you encoded the Mat to JPG twice - once using OpenCV and once using Swing. That duplication is unnecessary and the OpenCV is much easier to add compression so here's my suggestion of removing the Swing JPG encoding and adding Quality to OpenCV JPG encoding. The method name Mat2bufferedImage isn't as precise anymore and should be changed.

Change this in run() pushImage(imag, 10); // example of low quality, high compression

   public void pushImage(Mat frame, int quality) throws IOException {
        if (frame == null)
            return;
        try {
            outputStream = socket.getOutputStream();

            byte[] imageBytes = Mat2bufferedImage(frame, quality);

            outputStream.write(("Content-type: image/jpeg\r\n" +
                    "Content-Length: " + imageBytes.length + "\r\n" +
                    "\r\n").getBytes());

            outputStream.write(imageBytes);

            outputStream.write(("\r\n--" + boundary + "\r\n").getBytes());

        } catch (Exception ex) {
            socket = serverSocket.accept();
            writeHeader(socket.getOutputStream(), boundary);
        }
    }
   
    public static byte[] Mat2bufferedImage(Mat image, int quality) throws IOException {

        // jpg quality; 0 high compression to 100 low compression

        MatOfByte bytemat = new MatOfByte();

        MatOfInt parameters = new MatOfInt(Imgcodecs.IMWRITE_JPEG_QUALITY, quality); // pair-wise; param1, value1, ...

        Imgcodecs.imencode(".jpg", image, bytemat, parameters);

        return bytemat.toArray();
    }

Can you explain this code?

I can't understand this codes.

stream.write(("HTTP/1.0 200 OK\r\n" +
            "Connection: close\r\n" +
            "Max-Age: 0\r\n" +
            "Expires: 0\r\n" +
            "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" +
            "Pragma: no-cache\r\n" +
            "Content-Type: multipart/x-mixed-replace; " +
            "boundary=" + boundary + "\r\n" +
            "\r\n" +
            "--" + boundary + "\r\n").getBytes());
    }

And this

https://github.com/mesutpiskin/opencv-live-video-stream-over-http/blob/master/src/main/java/HttpStreamServer.java#L59

Can you explain this?

How to add native library for linux ?

I added the opencv's native library for windows.

but, how can I add the opencv's native library for both linux 32 bit and 64 bit?

Screenshot_20200626-201013_Edge

In opencv release page there is no downloading option for linux. Then , How can I add the native library ?

where to download the opencv's native library for linux ?

Help me!!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.