void PushbroomStereo::ProcessImages2(InputArray _leftImage, InputArray _rightImage, std::vector<Point3f> *pointVector3d, std::vector<Point3i> *pointVector2d, std::vector<uchar> *pointColors) { Mat leftImage = _leftImage.getMat(); Mat rightImage = _rightImage.getMat(); // make sure that the inputs are of the right type CV_Assert(leftImage.type() == CV_8UC1 && rightImage.type() == CV_8UC1); //Mat remapped_left(state.mapxL.rows, state.mapxL.cols, leftImage.depth()); //Mat remapped_right(state.mapxR.rows, state.mapxR.cols, rightImage.depth()); //INTEREST_OP步骤,拉普拉斯变换 Mat laplacian_left(leftImage.rows, leftImage.cols, leftImage.depth()); Mat laplacian_right(rightImage.rows, rightImage.cols, rightImage.depth()); Laplacian(leftImage,laplacian_left, -1, 3, 1, 0, BORDER_DEFAULT); Laplacian(rightImage,laplacian_right, -1, 3, 1, 0, BORDER_DEFAULT); //imshow("Laplac_L", laplacian_left); //imshow("Laplac_R", laplacian_right); //while( 1 ) //{ // waitKey( 100 ); //} RunStereoPushbroomStereo2(leftImage, rightImage,laplacian_left,laplacian_right, pointVector3d,pointVector2d,pointColors); }
/** * Runs the fast, single-disparity stereo algorithm. Returns a * vector of points where it found disparity matches in the image. * * @param _leftImage left camera image as a CV_8UC1 * @param _rightImage right camera image as a CV_8UC1 * @param hitVector a cv::vector that we will populate with cv::Point()s * @param state set of configuration parameters for the function. * You can change these on each run of the function if you'd like. */ void PushbroomStereo::ProcessImages(Mat leftImage, Mat rightImage, cv::vector<Point3f> *pointVector3d, cv::vector<uchar> *pointColors, cv::vector<Point3i> *pointVector2d, PushbroomStereoState state) { //cout << "[main] entering process images" << endl; // make sure that the inputs are of the right type CV_Assert(leftImage.type() == CV_8UC1 && rightImage.type() == CV_8UC1); // we want to use the sum-of-absolute-differences (SAD) algorithm // on a single disparity // split things up so we can parallelize int rows = leftImage.rows; StopWatchInterface *timer; sdkCreateTimer( &timer ); sdkResetTimer( &timer ); sdkStartTimer( &timer ); // first parallelize remaping // we split these arrays up and send them into each // thread so at the end, each thread has written to the // appropriate spot in the array Mat remapped_left(state.mapxL.rows, state.mapxL.cols, leftImage.depth()); Mat remapped_right(state.mapxR.rows, state.mapxR.cols, rightImage.depth()); remap( leftImage, remapped_left, state.mapxL, Mat(), INTER_NEAREST); remap( rightImage, remapped_right, state.mapxR, Mat(), INTER_NEAREST); sdkStopTimer( &timer ); //printf("remap timer: %.2f ms \n", sdkGetTimerValue( &timer) ); sdkResetTimer( &timer ); sdkStartTimer( &timer ); Mat laplacian_left(remapped_left.rows, remapped_left.cols, remapped_left.depth()); Mat laplacian_right(remapped_right.rows, remapped_right.cols, remapped_right.depth()); // apply interest operator Laplacian( remapped_left, laplacian_left, -1, 3, 1, 0, BORDER_DEFAULT); Laplacian( remapped_right, laplacian_right, -1, 3, 1, 0, BORDER_DEFAULT); sdkStopTimer( &timer ); //printf("laplacian timer: %.2f ms \n", sdkGetTimerValue( &timer) ); sdkResetTimer( &timer ); sdkStartTimer( &timer ); cv::vector<Point3f> pointVector3dArray; cv::vector<Point3i> pointVector2dArray; cv::vector<uchar> pointColorsArray; //cout << "[main] firing worker threads..." << endl; if (state.lastValidPixelRow > 0) { // crop image to be only include valid pixels rows = state.lastValidPixelRow; } int rows_round = RoundUp(rows, state.blockSize); RunStereoPushbroomStereo( remapped_left, remapped_right, laplacian_left, laplacian_right, pointVector3d, pointVector2d, pointColors, 0, rows_round - 1, state ); sdkStopTimer( &timer ); //printf("RunStereo timer: %.2f ms \n", sdkGetTimerValue( &timer) ); int numPoints = 0; // compute the required size of our return vector // this prevents multiple memory allocations numPoints = pointVector3dArray.size(); pointVector3d->reserve(numPoints); pointColors->reserve(numPoints); pointVector3d->insert( pointVector3d->end(), pointVector3dArray.begin(), pointVector3dArray.end() ); pointColors->insert( pointColors->end(), pointColorsArray.begin(), pointColorsArray.end() ); if (state.show_display) { pointVector2d->insert( pointVector2d->end(), pointVector2dArray.begin(), pointVector2dArray.end() ); } }