IE-482-582 / spring2024

3 stars 0 forks source link

Camera Code #51

Open cmurray3 opened 7 months ago

cmurray3 commented 7 months ago

The two attached Python scripts (olab_camera.py and olab_utils.py) can be used for several image processing activities. One such activity is camera calibration.

Unfortunately, I haven't had a chance to document the code...it's rather messy. Below is my attempt to explain how to run the camera calibration:

Installation

You may save the two .py scripts anywhere on your system. The ssl directory should be saved in ~/Projects.

Camera Calibration

The Python code below should be executed from the directory where you saved olab_camera.py and olab_utils.py:

import olab_camera

# /dev/video0 is my laptop webcam.  Your camera may be listed as a different `device`.
cam = olab_camera.CameraUSB(paramDict={'res_rows':480, 'res_cols':640, 'fps_target':30, 'outputPort':8000}, device='/dev/video0', fourcc='MJPG', initROSnode=False)

# Start the camera:
cam.start()

# Make the camera stream so we can watch it in a web browser:
cam.startStream(port=8000)
# Visit https://localhost:8000/stream.mjpg

# Start calibration.  The camera will take a series of pictures and will output the camera's intrinsic parameters.
cam.addCalibrate(secBetweenImages=3, numImages=25, timeoutSec=20, pattern_size=(6,8), square_size=0.0254):
'''
secBetweenImages:  How many seconds the camera will pause between taking pics.
numImages:  How many total pictures to use in the calibration.
timeoutSec:  If no grid is found in this time, the calibration procedure will terminate.  
pattern_size:  I'm not sure if this is (rows, cols), or (cols, rows).  A (9,6) pattern may be found here: https://github.com/opencv/opencv/blob/4.x/doc/pattern.png
square_size:  Size of each square, in meters.  
''' 

IE_482_582_camera_code.zip

btle1 commented 7 months ago

import olab_camera Traceback (most recent call last): File "", line 1, in File "/home/btle/Downloads/IE_482_582_camera_code/olab_camera.py", line 8, in import olab_utils # FIXME -- What is in here? File "/home/btle/Downloads/IE_482_582_camera_code/olab_utils.py", line 97, in "csrt": cv2.TrackerCSRT_create, AttributeError: module 'cv2' has no attribute 'TrackerCSRT_create'

shardulsaptarshi commented 6 months ago

same bug as btle1

cmurray3 commented 6 months ago

Those of you were were getting an error, please do the following and share your output:


First, open a Python session:

python3

Now, import openCV and check the version:

import cv2
cv2.__version__

1) Please let me know the version number


Next, try the following from within your Python session (after importing cv2)

cv2.Tr         # Now, start hitting the `tab` key a few times.

2) What auto-complete options are provided vor cv2.Tr?

Similarly, try this:

cv2.legacy.       # Note the trailing `.`.  Start hitting `tab`

3) What auto-complete options are provided for cv2.legacy.?

cmurray3 commented 6 months ago

Just thought of another thing to check to help us fix this issue. From an Ubuntu terminal (not in Python), type the following:

pip3 show opencv-contrib-python

4) What is the output from that command?

shardulsaptarshi commented 6 months ago

1)cv2 version is 4.9.0 these are the options i have:

2)>>> cv2.Tracker cv2.Tracker( cv2.TrackerMIL_Params( cv2.TrackerDaSiamRPN( cv2.TrackerMIL_create( cv2.TrackerDaSiamRPN_Params( cv2.TrackerNano( cv2.TrackerDaSiamRPN_create( cv2.TrackerNano_Params( cv2.TrackerGOTURN( cv2.TrackerNano_create( cv2.TrackerGOTURN_Params( cv2.TrackerVit( cv2.TrackerGOTURN_create( cv2.TrackerVit_Params( cv2.TrackerMIL( cv2.TrackerVit_create(

3)there are no autocomplete options for cv2.legacy.

4)student@ubuntu:~$ pip3 show opencv-contrib-python Name: opencv-contrib-python Version: 4.9.0.80 Summary: Wrapper package for OpenCV python bindings. Home-page: https://github.com/opencv/opencv-python Author: None Author-email: None License: Apache 2.0 Location: /usr/local/lib/python3.8/dist-packages Requires: numpy, numpy Required-by:

cmurray3 commented 6 months ago

Try the following:

sudo pip uninstall opencv-contrib-python
sudo pip uninstall opencv-python
sudo pip3 install opencv-contrib-python

Then, tell me what happens when running these commands:

python3
import cv2
cv2.TrackerCSRT_create()
shardulsaptarshi commented 6 months ago

Did those steps, this is what i get.

import cv2 cv2.TrackerCRST_create() Traceback (most recent call last): File "", line 1, in AttributeError: module 'cv2' has no attribute 'TrackerCRST_create'

shardulsaptarshi commented 6 months ago

Just FYI, I went through a couple steps to get my VM to actually recognize my camera

cmurray3 commented 6 months ago

Just FYI, I went through a couple steps to get my VM to actually recognize my camera

Could you post those steps, in case others are facing similar issues?

cmurray3 commented 6 months ago

Did those steps, this is what i get.

import cv2 cv2.TrackerCRST_create() Traceback (most recent call last): File "", line 1, in AttributeError: module 'cv2' has no attribute 'TrackerCRST_create'

You have a typo. Please try this exactly:

import cv2
cv2.TrackerCSRT_create()   
tallan232 commented 6 months ago

1) 4.9.0 2) cv2.Tracker( cv2.TrackerGOTURN( cv2.TrackerKCF_Params( cv2.TrackerNano_create( cv2.TrackerCSRT( cv2.TrackerGOTURN_Params( cv2.TrackerKCF_create( cv2.TrackerVit( cv2.TrackerCSRT_Params( cv2.TrackerGOTURN_create( cv2.TrackerMIL( cv2.TrackerVit_Params( cv2.TrackerCSRT_create( cv2.TrackerKCF( cv2.TrackerMIL_Params( cv2.TrackerVit_create( cv2.TrackerDaSiamRPN( cv2.TrackerKCF_CN cv2.TrackerMIL_create(
cv2.TrackerDaSiamRPN_Params( cv2.TrackerKCF_CUSTOM cv2.TrackerNano(
cv2.TrackerDaSiamRPN_create( cv2.TrackerKCF_GRAY cv2.TrackerNano_Params( 3) cv2.legacy.MultiTracker( cv2.legacy.TrackerCSRT_create( cv2.legacy.TrackerMOSSE_create( cv2.legacy.MultiTracker_create( cv2.legacy.TrackerKCF( cv2.legacy.TrackerMedianFlow( cv2.legacy.Tracker( cv2.legacy.TrackerKCF_create( cv2.legacy.TrackerMedianFlow_create( cv2.legacy.TrackerBoosting( cv2.legacy.TrackerMIL( cv2.legacy.TrackerTLD( cv2.legacy.TrackerBoosting_create( cv2.legacy.TrackerMIL_create( cv2.legacy.TrackerTLD_create( cv2.legacy.TrackerCSRT( cv2.legacy.TrackerMOSSE( cv2.legacy.upgradeTrackingAPI( 4) Name: opencv-contrib-python Version: 4.9.0.80 Summary: Wrapper package for OpenCV python bindings. Home-page: https://github.com/opencv/opencv-python Author: None Author-email: None License: Apache 2.0 Location: /usr/local/lib/python3.8/dist-packages Requires: numpy, numpy Required-by:

Then after sudo uninstall, install open cv, etc.. < cv2.TrackerCSRT 0x7eff82f8cfd0>

tallan232 commented 6 months ago

https://arxiv.org/pdf/1908.01450 page 6 contains the following table:

image