PTZ does not work
Published by Margarito Lehmann on
- May 26, 2020 at 9:52 pm #23124Margarito LehmannParticipant
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.
- May 27, 2020 at 7:06 pm #23178binKeymaster
In order to help you debug it, I need detail error messages and your detail operation steps.
- July 11, 2020 at 3:26 pm #25023
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.
- July 12, 2020 at 6:57 pm #25045binKeymaster
Great to hear you have solved your problem. For the openCV, which need X11 display system, you can’t run it in remote terminal.
- July 12, 2020 at 7:41 pm #25051
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.
- July 13, 2020 at 7:15 pm #25067
- July 14, 2020 at 4:28 am #25082
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.
- July 14, 2020 at 4:45 am #25083
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?
- July 14, 2020 at 6:32 pm #25087wongModerator
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?
- July 15, 2020 at 3:29 am #25149
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!
- You must be logged in to reply to this topic.