Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

880
Visualizações
Unity + OpenCV + Python (integreation)

there is a need to combine Unity3d and OpenCV (preferably with NumPy, since functions will also be used from there, which means +Python is also needed). The main idea is to pass images from camera from Unity to OpenCV for processing and then sending actions back to Unity.

I've tried many variants, made by taking picture bytes stream from RenderTexture (Unity) and sending it to python server on websockets. Everything works, and the transfer speed is acceptable, but during the "photographing" of the texture it takes a lot of resources and the main thread of Unity hangs... so I get 5 fps, which is not good. I want to rewrite it the right way: either integrate openCV into unity, or pull texture from video memory (but that's horrible C++ and openGL, I want to get python, because I need numPy).

I tried streaming with FMETP STREAM (it has not started front end, which means it works, but image is not displayed in browser), then put in IronPython openCV and use them in C# (I can not install opencv in any way), tried to put modules for C#: OpenCVSharp (seems to be ok with this package), NumSharp (lacks some methods to be used in the project), and socket image transfer method (works, but awfully long and lags). .. in each variant tried and studied almost everything thoroughly.

Actually, I wanted to ask for advice, which integration is better to choose, how to do it better?

Code I use to send image bytes to python server: https://pastebin.com/pRyutRcj

    WebSocket ws;

    void Start () {

        ws = WebSocketFactory.CreateInstance("ws://localhost:12345");

        // ...

        // Connect to the server
        ws.Connect();

        InvokeRepeating("Capture", 1f, 0.2f);  //1s delay, repeat every 1s

    }

    public void Capture()
    {
        RenderTexture activeRenderTexture = RenderTexture.active;
        RenderTexture.active = Camera.targetTexture;

        Camera.Render();

        Texture2D image = new Texture2D(Camera.targetTexture.width, Camera.targetTexture.height);
        image.ReadPixels(new Rect(0, 0, Camera.targetTexture.width, Camera.targetTexture.height), 0, 0);
        image.Apply();
        RenderTexture.active = activeRenderTexture;

        byte[] bytes = image.EncodeToPNG();
        Destroy(image);


        ws.Send(bytes);
    }
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Your original solution is running everything in your main thread on unity. Thus, it will lag as expected. And you are encoding as PNG, the data will be huge.

In FMETP STREAM, they used multi-threading encoder, which should at least solve your performance issue. That's why it can run smoothly on low-end device and VR headsets.

The output byte[] are chunks of jpeg, instead of one image. It was designed for UDP packet size limit.

If you try to decode FMETP STREAM's image on your own, you have to combine those byte[] into one complete jpeg. It won't be too difficult referring to their decoder in C#.

PS: For technical support, please contact the developer directly.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda