Webcamjs - Function does not work sometimes

Asked

Viewed 242 times

0

I have this javascriptt function, which is when you take the webcam photo, it works, but there are times when the "webcam.snap()" part doesn’t work. I do not understand why, there are hours that it works, and there are hours that does not, it does not return any error on the console. Follow the code part :

function take_snapshot() {
  document.getElementById('upload_results').innerHTML = '<h1>Realizando Upload da Foto...</h1>';
  webcam.snap();
  document.getElementById('<%=btnFechaPopWebCam.ClientID%>').click();
}

So much so that he even clicks Closepopwebcam, but he doesn’t always perform the webcam.snap() function; And this is where I call the take_snapshot function()

<input type="button" value="Capturar" class="btn btn-default" onclick="take_snapshot();" />

Something strange that happens, is that if I put the breakpoint it always works right, but when I don’t put, sometimes it doesn’t work.

I used this link as a reference.

  • 1

    Please put a [mcve] that displays the problem.

  • It was updated, I put as I call the take_snapshot() function, as explained not always the webcam.snap function works. It skips it, but it works the button click right away.

  • 1

    An EMCV needs a little more than that. The way it is, we can’t understand what the problem is because we can’t reproduce. Read the [mcve] page if you don’t know what this is.

  • Sometimes the webcam.snap() function works, and sometimes it doesn’t. I use this library: https://github.com/jhuckaby/webcamjs/blob/master/webcam.js

  • Post a functional code so we can test, just the way this one doesn’t know how you set up the webcam

  • This library you are using is in maintenance mode and has over 90 open bugs. The project’s own Readme suggests other libraries.

  • http://leonelfraga.com/neomatrixtech/posts/2012/04/capturndo-a-imagem-de-uma-webcam-em-paginas-asp-net-salvando-o-cadastro-em-banco-dados.html I used this link as a reference.

Show 2 more comments

1 answer

0


According to the documentation, you need to pass a callback function as parameter to be executed after the snap.

To snap a picture, just call the Webcam.snap() Function, Passing in a callback Function. The image data will be passed to your Function as a Data URI, which you can then display in your web page, or Submit to a server. Example:
Webcam.snap( function(data_uri) {
    document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';
} );

  • Andre, I saved it right into the database, in which case it wouldn’t be if I were to save it to a directory ? I updated the question, with the link I used as reference.

  • Are you using the JS provided by him at the end of the article? Are you setting the hook?

  • Yes, I’m using the same, and I’m referencing at the top of the page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.