1. 程式人生 > >OPENCV----在APP性能測試中的應用(一)

OPENCV----在APP性能測試中的應用(一)

核心 color frame pan ems span urn sqrt ||

應用項目: APP的性能測試

應用場景: APP啟動速度 視頻開播速度 加載速度 等~~

緣來: 基於APP日誌UiAutomator的測試方案,測試結果不能直白且精確的反應,用戶的體驗

改進: 通過手工操作或自動操作的方式錄取視頻,然後用圖像處理的方式,來獲取測試結果

架構流程圖:

技術分享

主要的核心點:

  視頻分幀: 基於ffmpeg庫 進行分幀

樣例: ffmpeg -hide_banner -i video.mp4 -an -vsync 0 .\frames\%06d.png > null

圖片對比: 基於opencv庫進行圖片對比

核心代碼:

int diff_count(const Mat& lmat, const Mat& rmat, int threshold) {
    int cols = lmat.cols;
    int rows = lmat.rows;
    int esize = (int)lmat.elemSize();

    if ( rmat.cols != cols || rmat.rows != rows || (int)rmat.elemSize() != esize ) {
        return -1;
    }

    int total = rows * cols;
    
int dcount = 0; for ( int i = 0; i < total; i++ ) { uchar* lptr = lmat.data + i*esize; uchar* rptr = rmat.data + i*esize; int sum = 0; for ( int j = 0; j < esize; j++ ) { uchar lu = lptr[j]; uchar ru = rptr[j]; int tmp = lu > ru ? lu - ru : ru - lu; sum
+= tmp*tmp; } if ( sqrt(sum)/esize >= threshold ) { dcount++; } } return dcount; }

OPENCV----在APP性能測試中的應用(一)