Ask Your Question

renzbagaporo's profile - activity

2015-09-05 06:22:18 -0500 commented question Missing trackbars in OpenCV

Actually, that's what I did. I edited my post to include the code relevant to the creation of trackbars.

2015-09-05 06:21:21 -0500 received badge  Editor (source)
2015-09-05 05:38:23 -0500 asked a question Missing trackbars in OpenCV

I have 8 trackbars for my application. However, when the window is displayed, the last trackbar is missing. I tried setting the window to CV::WINDOW_NORMAL, making the window resizable. Resizing the window shows the missing trackbar. Is there a way to dispay the all the trackbars without resizing?

Edit: Added the code relevant to the question at hand. settings_window and views_window are const strings.

void image_demo::exec(){
    //Initialize the UI
    cv::namedWindow(settings_window/*,CV_WINDOW_NORMAL*/);

    //Create the trackbars
    cv::createTrackbar("COST", settings_window, &ad_gamma, 100, on_trackbar, this);
    cv::createTrackbar("ARM_L", settings_window, &arm_length, 100, on_trackbar, this);
    cv::createTrackbar("M_ARM_L", settings_window, &max_arm_length, 100, on_trackbar, this);
    cv::createTrackbar("ARM_T", settings_window, &arm_threshold, 100, on_trackbar, this);
    cv::createTrackbar("S_ARM_T", settings_window, &strict_arm_threshold, 100, on_trackbar, this);

    cv::createTrackbar("VOTE_I", settings_window, &bfv_iterations, 10, on_trackbar, this);
    cv::createTrackbar("MED_SZ", settings_window, &medfilt_size, 15, on_trackbar, this);
    cv::createTrackbar("DISP_T", settings_window, &disparity_tolerance, 10, on_trackbar, this);

    cv::Mat left_frame, right_frame, disp_frame, demo_frame;
    frame.get_frames(left_frame, right_frame);

    cv::Mat grid_view_im;

    while (true){
        if (!matcher.compute(frame, disp_frame) && run) break;
        demo_frame = disp_frame.clone();
        grid_view_im = disp_frame.clone();
        cv::imshow(views_window, grid_view_im);
        handle_key(cv::waitKey(25));
    }
    return;
}
2015-06-23 22:21:25 -0500 asked a question OpenCV cudastereo samples gray window for BP and CSBP

Hi! I ran the cudastereo sample "gpu-example-stereo_match.exe" to see how well the stereo algorithms in OpenCV work. However, the CSBP and BP implementations just show a gray window. The BM one works fine.

2015-06-07 04:25:14 -0500 received badge  Enthusiast
2015-05-31 01:00:10 -0500 asked a question Implementation of Absolute Differences Stereo Matching Algorithm

Good day!

I am trying to learn how to manually implement stereo matching algorithms. I'm basically starting with the most basic of them all - Absolute Difference.

I found some slides online that describe how to do it. Basically, from what I understand, I should calculate the difference between the pixels in my left image and the same pixel in the right image "shifted" by a certain distance/disparity. Then among these disparities, I select the minimum, which makes sense to me since the pixel with the lowest disparity means that it is most likely the same pixel in the left image.

I've coded it in OpenCV. Here is the code:

include <opencv2\opencv.hpp>
#include "support.h"

int main(){
    cv::Mat left_img = cv::imread("..\\images\\middlebury\\tsu_left.png", cv::IMREAD_GRAYSCALE);
    cv::Mat right_img = cv::imread("..\\images\\middlebury\\tsu_right.png", cv::IMREAD_GRAYSCALE);

    int disparity_max = 64;

    std::vector<cv::Mat> cost_maps;

    for (int disparity = 0; disparity < disparity_max; disparity++){
        cv::Mat cost_map = cv::Mat(left_img.size().height, left_img.size().width, CV_8UC1);
        for (int row = 0; row < left_img.size().height; row++){
            for (int col = 0; col < left_img.size().width; col++){
                int col_disp = (col - disparity < 0) ? 0 : col - disparity;
                            //Absolute Difference
                cost_map.at<uchar>(row, col) = abs(left_img.at<uchar>(row, col) - right_img.at<uchar>(row, col_disp));
            }
        }
        cost_maps.push_back(cost_map);
        show(cost_map);
    }


    //Pick the smallest disparity
    cv::Mat final_cost_map = cv::Mat(left_img.size().height, left_img.size().width, CV_8UC1);
    for (int row = 0; row < final_cost_map.size().height; row++){
        for (int col = 0; col < final_cost_map.size().width; col++){

            int min = 65536;
            for (int disparity = 0; disparity < disparity_max; disparity++){
                min = (cost_maps[disparity].at<uchar>(row, col) < min ? cost_maps[disparity].at<uchar>(row, col) : min);
            }

            final_cost_map.at<uchar>(row, col) = min;

        }
    }

    //Show the final cost map, multiplied by 32 to show pixels with low value
    show(final_cost_map * 32);
}

Take note that I haven't implemented the variant where the differences in a certain window is summed, leading to Sum of Absolute Differences. I am only taking the difference per pixel, per disparity. The lecture slides I found online says that it should look like this (rightmost image):

https://dl.dropboxusercontent.com/u/9...

However, the result from the code above yield something like this:

https://www.dropbox.com/s/7ns7h6tqycj...

I can't figure out why the outputs are so different. Is there some trivial step that I am missing, or is my understanding of how the algorithm works wrong? I am also using the tsukuba image.