當前位置: 華文星空 > 知識

Apollo camera驅動分析(二十九)

2021-11-22知識

相機驅動分為2部份,一部份在目錄 modules\drivers\camera 中,為USB介面,另一部份在目錄 modules\drivers\video 中,為網口。接下來我們開始分別介紹這2部份。

Camera目錄

camera主要分為2個模組:

  1. CameraComponent 模組。負責從USB介面讀取圖片。
  2. CompressComponent 模組。負責壓縮圖片,減少傳輸大小。

由於可以接入多個camera相機,如果工控機或者主機上的USB介面不夠用,需要接入USB-HUB,這裏需要註意HUB的頻寬,如果頻寬不夠則需要接入多個HUB,同時還需要註意HUB是否支持並行,否則每次只能啟用其中的一個相機,具體可以參考USB協定。

1. camera模組

CameraComponent 模組會讀取 conf 目錄中相機的配置,包括圖片的格式、長寬等,這裏需要註意調整照片大小不要超過 MAX_IMAGE_SIZE

camera模組透過 UsbCam 類來讀取照片,並且釋出。 UsbCam 呼叫了linux v4l2 的介面,v4l2為linux下視訊裝置程式提供了一套介面規範。

2. 影像壓縮模組

CompressComponent 模組接收圖片,並且透過 cv::imencode 介面進行壓縮,方便網路傳輸。

3. 影像解壓

影像解壓的功能是在tools目錄下提供的,做為一個工具提供,目錄在 modules\drivers\tools\image_decompress 。接收壓縮的影像,輸出解壓的影像。采用 cv::imdecode 進行解壓。

cv :: Mat mat_image = cv :: imdecode ( compressed_raw_data , cv :: IMREAD_COLOR ); cv :: cvtColor ( mat_image , mat_image , cv :: COLOR_BGR2RGB ); image -> set_width ( mat_image . cols ); image -> set_height ( mat_image . rows ); // Now olny rgb image -> set_encoding ( "rgb8" ); image -> set_step ( 3 * image -> width ());

Video目錄

video模組主要是透過乙太網路口來讀取相機數據,其中相機的配置在 conf 目錄中,從配置中可以發現

required string trigger_param = 21 [ default = "f2ff" ]; // 觸發參數 required uint32 metric_error_code = 22 [ default = 11 ]; required int32 fpga_dev_number = 23 [ default = - 1 ]; // FPGA編號

也就是說 采用了FPGA做為硬體觸發源來觸發相機拍照 ,從而實作硬體時間同步,這有2個好處,一是保證多個相機之間的時間同步,而是保證相機和雷射雷達之間的時間同步。

1. CompCamerap65Compressed模組

CompCamerap65Compressed模組初始化的時候會啟動一個執行緒來讀取相機數據

video_thread_ = std :: shared_ptr < std :: thread > ( new std :: thread ( std :: bind ( & CompCamerap65Compressed :: VideoPoll , this ))); video_thread_ -> detach ();

讀取數據是透過 CameraDriver 類來實作的。如果配置檔中 record:1 則會同時寫入圖片到硬碟,如果為0則不寫入。

2. CameraDriver

CameraDriver類透過SocketInput類,透過socket介面讀取視訊流。

3. Tools

最後介紹下tools目錄下的 video2jpg ,用來把video轉換為圖片。透過命令列指定

  1. input_video。需要轉換的視訊
  2. output_dir。輸出的資料夾

FrameProcessor 類中封裝了 p65Decoder 進行解碼,關於視訊編解碼這塊可以參考ffmepg的編程,包括硬解碼(借助特殊硬體解碼)、軟解碼(直接透過軟體解碼)。

總結

以上介紹了2種相機接入方式:USB介面和網口。USB介面一般輸出是圖片,而網口一般輸出為視訊流,同時為了保持硬體同步,有些相機還支持trigger觸發的方式來獲取圖片,結合特定的硬體(FPGA)就可以實作。

透過把視訊流上傳,然後遠端觀看的方式,可以實作遠端駕駛的監控畫面。

往期回顧

  • apollo介紹(一)
  • apollo介紹之map模組(二)
  • apollo介紹之localization模組(三)
  • apollo介紹之planning模組(四)
  • apollo介紹之Routing模組(六)
  • apollo介紹之Transform模組(七)
  • apollo介紹之Canbus模組(八)
  • apollo介紹之Control模組(九)
  • apollo介紹之Perception模組(十七)
  • apollo介紹之Audio模組(十八)
  • apollo預測模組分享(二十一)
  • apollo汽車底盤適配(二十六)
  • apollo介紹之參考線(二十七)
  • 硬體驅動

  • Apollo Lidar驅動分析(二十八)
  • Apollo camera驅動分析(二十九)
  • Apollo radar驅動分析(三十)
  • Cyber框架

  • apollo介紹之cyber設計(五)
  • apollo介紹之Cyber框架(十)
  • apollo介紹之Cyber框架(十一)
  • apollo介紹之Cyber定時器(十二)
  • apollo介紹之Cyber Component(十三)
  • apollo介紹之Cyber Data(十四)
  • apollo介紹之Cyber Scheduler排程(十五)
  • apollo介紹之Cyber Async異步呼叫(十六)
  • apollo介紹之cyber啟動(十九)
  • 高精度地圖

  • apollo介紹之map模組(二)
  • 高精度地圖制作
  • 高精度地圖制作(二)
  • 高精度地圖制作(三)
  • apollo簡易制圖過程(二十)
  • apollo高精度地圖視覺化(二十二)
  • apollo高精度地圖制作(二十三)
  • apollo高精度地圖示註(二十四)