Add openpilot tools

This commit is contained in:
FrogAi
2024-01-12 22:39:30 -07:00
parent d1bee2c971
commit 0174873f46
154 changed files with 16477 additions and 0 deletions

41
tools/webcam/Dockerfile Normal file
View File

@@ -0,0 +1,41 @@
FROM ghcr.io/commaai/openpilot-base:latest
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH /tmp/openpilot:${PYTHONPATH}
# Install opencv
ENV OPENCV_VERSION '4.2.0'
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
libvtk6-dev \
libdc1394-22-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libtheora-dev \
libvorbis-dev \
libxvidcore-dev \
libx264-dev \
yasm \
libopencore-amrnb-dev \
libopencore-amrwb-dev \
libv4l-dev \
libxine2-dev \
libtbb-dev \
&& rm -rf /var/lib/apt/lists/* && \
mkdir /tmp/opencv_build && \
cd /tmp/opencv_build && \
curl -L -O https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.tar.gz && \
tar -xvf ${OPENCV_VERSION}.tar.gz && \
mv opencv-${OPENCV_VERSION} OpenCV && \
cd OpenCV && mkdir build && cd build && \
cmake -DWITH_OPENGL=ON -DFORCE_VTK=ON -DWITH_TBB=ON -DWITH_GDAL=ON \
-DWITH_XINE=ON -DENABLE_PRECOMPILED_HEADERS=OFF -DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_opencv_apps=OFF .. && \
make -j8 && \
make install && \
ldconfig && \
cd / && rm -rf /tmp/*

45
tools/webcam/README.md Normal file
View File

@@ -0,0 +1,45 @@
# NOTE: this README is outdated. #24590 tracks adding back webcam support
# Run openpilot with webcam on PC
What's needed:
- Ubuntu 20.04
- GPU (recommended)
- Two USB webcams, at least 720p and 78 degrees FOV (e.g. Logitech C920/C615)
- [Car harness](https://comma.ai/shop/products/comma-car-harness) with black panda to connect to your car
- [Panda paw](https://comma.ai/shop/products/panda-paw) or USB-A to USB-A cable to connect panda to your computer
That's it!
## Setup openpilot
```
cd ~
git clone https://github.com/commaai/openpilot.git
```
- Follow [this readme](https://github.com/commaai/openpilot/tree/master/tools) to install the requirements
- Add line "export PYTHONPATH=$HOME/openpilot" to your ~/.bashrc
- Install tensorflow 2.2 and nvidia drivers: nvidia-xxx/cuda10.0/cudnn7.6.5
- Install [OpenCL Driver](https://registrationcenter-download.intel.com/akdlm/irc_nas/vcp/15532/l_opencl_p_18.1.0.015.tgz)
- Install [OpenCV4](https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/) (ignore the Python part)
## Build openpilot for webcam
```
cd ~/openpilot
```
- check out system/camerad/cameras/camera_webcam.cc lines 72 and 146 before building if any camera is upside down
```
USE_WEBCAM=1 scons -j$(nproc)
```
## Connect the hardware
- Connect the road facing camera first, then the driver facing camera
- (default indexes are 1 and 2; can be modified in system/camerad/cameras/camera_webcam.cc)
- Connect your computer to panda
## GO
```
cd ~/openpilot/selfdrive/manager
NOSENSOR=1 USE_WEBCAM=1 ./manager.py
```
- Start the car, then the UI should show the road webcam's view
- Adjust and secure the webcams (you can run tools/webcam/front_mount_helper.py to help mount the driver camera)
- Finish calibration and engage!

View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python
import numpy as np
# copied from openpilot.common.transformations/camera.py
eon_dcam_focal_length = 860.0 # pixels
webcam_focal_length = 908.0 # pixels
eon_dcam_intrinsics = np.array([
[eon_dcam_focal_length, 0, 1152/2.],
[ 0, eon_dcam_focal_length, 864/2.],
[ 0, 0, 1]])
webcam_intrinsics = np.array([
[webcam_focal_length, 0., 1280/2.],
[ 0., webcam_focal_length, 720/2.],
[ 0., 0., 1.]])
cam_id = 2
if __name__ == "__main__":
import cv2
trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))
cap = cv2.VideoCapture(cam_id)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
while (True):
ret, img = cap.read()
if ret:
img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1152, 864), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
img = img[:, -864//2:, :]
cv2.imshow('preview', img)
cv2.waitKey(10)

43
tools/webcam/warp_vis.py Normal file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python
import numpy as np
# copied from openpilot.common.transformations/camera.py
eon_focal_length = 910.0 # pixels
eon_dcam_focal_length = 860.0 # pixels
webcam_focal_length = -908.0/1.5 # pixels
eon_intrinsics = np.array([
[eon_focal_length, 0., 1164/2.],
[ 0., eon_focal_length, 874/2.],
[ 0., 0., 1.]])
eon_dcam_intrinsics = np.array([
[eon_dcam_focal_length, 0, 1152/2.],
[ 0, eon_dcam_focal_length, 864/2.],
[ 0, 0, 1]])
webcam_intrinsics = np.array([
[webcam_focal_length, 0., 1280/2/1.5],
[ 0., webcam_focal_length, 720/2/1.5],
[ 0., 0., 1.]])
if __name__ == "__main__":
import cv2
trans_webcam_to_eon_rear = np.dot(eon_intrinsics, np.linalg.inv(webcam_intrinsics))
trans_webcam_to_eon_front = np.dot(eon_dcam_intrinsics, np.linalg.inv(webcam_intrinsics))
print("trans_webcam_to_eon_rear:\n", trans_webcam_to_eon_rear)
print("trans_webcam_to_eon_front:\n", trans_webcam_to_eon_front)
cap = cv2.VideoCapture(1)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 853)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
while (True):
ret, img = cap.read()
if ret:
# img = cv2.warpPerspective(img, trans_webcam_to_eon_rear, (1164,874), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
img = cv2.warpPerspective(img, trans_webcam_to_eon_front, (1164, 874), borderMode=cv2.BORDER_CONSTANT, borderValue=0)
print(img.shape, end='\r')
cv2.imshow('preview', img)
cv2.waitKey(10)