cookbook-code icon indicating copy to clipboard operation
cookbook-code copied to clipboard

Problem with recipe 3.7

Open rossant opened this issue 9 years ago • 9 comments

Posted by Anand Muglikar.

I used the ipython notebook shown below which uses your code as a base:

http://nbviewer.ipython.org/github/ipython-books/cookbook-code/blob/master/notebooks/chapter03_notebook/07_webcam_py3.ipynb

On running the code, webcam opens but no video is seen on Iceweasel browser (firefox based). On Chrome, webcam just starts and immediately shuts. I'm a newbie in Python and do not know javascript. Please guide.

Thanks in advance! :)

rossant avatar Nov 05 '14 09:11 rossant

Which version of Python and IPython do you have? Any error messages? You can find error messages by pressing F12; this will open the Developer tools (at least on Chrome).

rossant avatar Nov 05 '14 09:11 rossant

Thanks for the reply Cyrille! :)

anand@anandeb:~$ python --version Python 2.7.6 :: Anaconda 1.9.2 (64-bit) anand@anandeb:~$ ipython --version 2.0.0

What exactly to look for in the developer tools? I want to do something like this using your code, because that code of jsfeat is quite complex for me. Is it possible?

http://inspirit.github.io/jsfeat/sample_haar_face.html

rossant avatar Nov 05 '14 09:11 rossant

Yes that's doable! Instead of applying an image filter Python-side, you can detect the face with something like OpenCV.

In the developer tools, look for potential errors in the "JavaScript console". Here is the doc for Chrome.

rossant avatar Nov 05 '14 09:11 rossant

Hi there,

I'm also trying to use recipe 3.7. In fact, I'm unable to get it to run. When I execute the last cell from the notebook that should display the constructed widget, nothing happens.

From the discussion above, I figured out that I needed to check the JS console, which I did. It turns out that the execution of the last cell throws a couple of errors. After battling a little bit more I found what seems to be the root cause for me:

Class CameraView not found in registry

So I figured that the code in the cell defining the CameraView is not working properly defining the CameraView. I tried to copy paste the code from the cell that defines CameraView directly into my JS console and got yet another error message:

TypeError: WidgetManager.register_widget_view is not a function

Could you please tell me what you think about this? I'd love to use your example and build upon it. Thanks!

flothesof avatar Mar 20 '15 18:03 flothesof

Are you using IPython 3.0? If so, that's expected. The widget interface has changed between 2.0 and 3.0 and I haven't had the time to upgrade the examples yet (it's on my list)... You'll find more information at http://ipython.org/ipython-doc/3/whatsnew/version3_widget_migration.html

rossant avatar Mar 20 '15 18:03 rossant

Yes, that's exactly the case. In fact, I initially didn't use IPython 3.0 but then the notebook was not readable: it complained that the nbformat used was not the right one... So downgrading again to IPython 2.x and converting to an acceptable nbformat should do the job? Thanks for your quick reply!

flothesof avatar Mar 20 '15 18:03 flothesof

Yeah I had to convert to the latest nbformat because the notebooks wouldn't work with IPython 3.0... but then the widgets are broken! Fortunately I think you should be able to open the notebooks if you install the very latest version of IPython 2.x: in principle they've backported the latest nbformat to the IPython 2.x branch. Let me know if it works (or not).

rossant avatar Mar 20 '15 18:03 rossant

I downgraded and now it works in Firefox, but not Safari. Thanks!

The JS code says something about being able to set it to play / pause. Should there be a button for this, or not really?

flothesof avatar Mar 20 '15 18:03 flothesof

I think there should be Play/Pause buttons in Google Chrome, not sure about Firefox.

rossant avatar Mar 20 '15 18:03 rossant