V
V
Victor P.2020-11-17 21:50:01
CCTV
Victor P., 2020-11-17 21:50:01

Why are there so many delays in taking a photo?

Good afternoon to all DYI lovers,
I'm going to make a streaming video from a raspberry via the Internet (a prerequisite) with a minimum delay (to control the robot in real time). I went according to the scheme that I take a lot of pictures, they are constantly updated and the impression of a video is created, it seems like the best option.
Given: I
use Raspberry Pi 3b+
I put one of the standard cameras on it via a cable.
Deployed a node.js application
Connected the node-raspistill package

'use strict';
var express = require('express');
var router = express.Router();
var http = require("http");
const Raspistill = require('node-raspistill').Raspistill;
const camera = new Raspistill({
  width: 640,
  height: 480,
  encoding: 'jpg'
});
/* GET home page. */
router.get('/', function (req, res) {
  
  sendPhoto();
   
});
function sendPhoto(){
  var startTime = new Date().getTime();
  var options = {
    hostname: '192.168.0.105',
    port: '5000',
    path: '/api/chat/push',
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    }
  };
  var remoteReq = http.request(options);
  camera.takePhoto().then((photo)=>{
    var baseStrImg = photo.toString('base64');
    var spanTime = (new Date().getTime() - startTime)/1000+'';
    console.log(spanTime);
    remoteReq.write(JSON.stringify({ message: baseStrImg, Time: spanTime}));
    remoteReq.end();
    sendPhoto();
  });
}
module.exports = router;


There is quite a bit of code here, I use the Raspistill constructor, in which I set the size to 640 by 480 and the jpg format. Pretty small photo size. Then, when a command comes from the browser, I take a picture from the camera, convert the image to base4, and additionally measure how long it takes and send the data to another server.
The photo is taken, approximately, 5.7 seconds (conversion from an array of bytes to base64, by the way, 0.1 seconds). Plus, of course, there are shipping costs.
As you can imagine, this is unrealistically long. I don't see any additional parameters/settings. I do not know what to do.
I've seen quite a few other packages, apparently I'll have to iterate through everything.
But maybe the community has already done a similar task? How did you deal with it? Overall, am I moving in the right direction?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mirilaczvili, 2020-11-18
@Jeer

That is, it camera.takePhoto()takes more than 5 seconds? Try checking the snapshot time using the command in the terminal, writing to RAM, not to the SD card.
If it's still long, then there is hardly a better solution when working with raspistill.

A
Alexander Skusnov, 2020-11-18
@AlexSku

I once made a mirroring program (left - right) for a laptop camera on DirectShow. The camera gave out 30 fps, all frames were processed at this speed. But one laptop (Samsung?) had lag and the other (HP?) didn't, so the laptop's camera driver is to blame. (the delay, of course, is not 5 seconds, but some fraction of a second, visible if you move your hand from side to side)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question