PTZ does not work

Published by Margarito Lehmann on

Viewing 9 reply threads
  • Author
    Posts
    • #23124
      Margarito Lehmann
      Participant

      Hello Arducam,

      My PTZ does not work. python FocuserExample.py shows preview for 1 second then program exits. Connected to Pi 4, using Python 2.7.16. Everything seems to be connected okay.

      Please advise. Thanks.

    • #23178
      bin
      Keymaster

      Hello,

      In order to help you debug it, I need detail error messages and your detail operation steps.

       

    • #25023
      fisha462
      Participant

      I had a difficult time getting this to work.  It had a lot to do with OpenCV installation.  Also when I run the code from the terminal, the import cv2 line fails.  If I run the code in an IDE with terminal it works.

    • #25045
      bin
      Keymaster

      Hi,

      Great to hear you have solved your problem. For the openCV, which need X11 display system, you can’t run it in remote terminal.

       

    • #25051
      fisha462
      Participant

      I had that problem initially as I tried to run the python script using a remote connection to my PI.  Once I used the connected monitor AND the Thonny Python IDE it worked.  When I tried to run the python script from a terminal it said it couldn’t import CV2.  I was using python3 though.  Anything I run the autofocus script, the program results in error and it does not focus.

    • #25067
      wong
      Moderator

      Hi @fisha462 ,

      Have you tried python2.7? If the IDE works, it means that you have a python version that works, please try multiple versions.

      By the way, if you still have problems please send us the error message.

      • This reply was modified 1 day, 14 hours ago by wong.
    • #25082
      fisha462
      Participant

      Wong,

      My IDE is using python 3.7.3.  Inside my IDE, I am using Numpy version 4.1.0 and OpenCV 1.16.2.  I am able to run the FocuserExample.py except when I hit “Enter”:

      When I try to run the AutoFocus.py, I get the following error:

      TypeError: slice indices must be integers or None or have an __index__ method on line 77:

      “image = image[(height / 4):((height / 4) * 3),(width / 4):((width / 4)) * 3]”.

      I did some research and it looks like you could do this in Numpy 1.11 but you can no longer in Numpy 1.12 and above.

      Do you have any suggestions?  I am trying to use this camera in conjunction with other code that will require never version of Python, OpenCV, and Numpy.  I am a relative novice with Python but I am stubborn so I will continue to attempt to make it work.  In the mean time, I will try to install OpenCV in Python 2, it looks like it takes a little bit of work to get it installed in that older version of Python.

      Thanks for your help.

      Aaron

    • #25083
      fisha462
      Participant

      Wong,

      I got the code to run on Python3.7 but changing all of the ‘/’ to ‘//’ where its trying to slice the index.  The code runs now but it doesn’t work very well.  I imagine taking those floats away made it lose it’s level of accuracy?

      Aaron

    • #25087
      wong
      Moderator

      fisha462,

      Changing the’/’ to’//’ is the correct approach, this should not affect accuracy.
      This focusing procedure is very simple, its accuracy is not very high, is there a big difference between you before and after modification?

    • #25149
      fisha462
      Participant

      Wong,

      I was never able to run the code in Python 2 so I can’t comment on the performance of the auto-focus code.  I have observed that the camera usually goes past the point of focus when I run the code in Python 3.  About 50% of the time I get a blurry image after running.  I have tried it with different levels of zoom and tried pointing the camera at different objects at different lengths away.  Once the code is finished I can always manually adjust the focus, it seems like the auto-focus code doesn’t adjust the zoom.  I should ask what is the intent of the code? Was it to give your customers a pure example that wasn’t mean’t to be used in a real application?  In other words can that code be improved upon?  It seems to me that it can be improved.  I am having a lot of fun doing this, I hope my questions are engaging for you as well!

      Thanks!

Viewing 9 reply threads
  • You must be logged in to reply to this topic.