void read_radiance(std::istream& in, radiance_reader& reader, bool invert_X, bool invert_Y, bool invert_Z) { std::string str; std::getline(in, str); if (str != "#?RADIANCE") throw std::runtime_error("not radiance format"); float exposure = 1.0f; float pixaspect = 1.0f; chromacity prim = chromacity::stdprims; V3 colour_correction(V3::mk(1.0f, 1.0f, 1.0f)); radiance_colour_format fmt = RADIANCE_FMT_UNKNOWN; while (in.good()) { std::getline(in, str); if (str == "") break; if (str[0] == '#') continue; std::string tag; std::istringstream inl(str); inl >> tag; if (tag == "EXPOSURE=") { inl >> exposure; } else if (tag == "PIXASPECT=") {
/*! * \brief calculates a disparity map given two images * \param img_left colour data for the left image2 * \param img_right colour data for the right image * \param img_width width of the image * \param img_height height of the image * \param offset_x calibration offset x * \param offset_y calibration offset y * \param vertical_sampling vertical sampling rate - we don't need every row * \param max_disparity_percent maximum disparity as a percentage of image width * \param correlation_radius radius in pixels used for patch matching * \param smoothing_radius radius in pixels used for smoothing of the disparity space * \param disparity_step step size for sampling different disparities * \param disparity_threshold_percent a threshold applied to the disparity map * \param despeckle optionally apply despeckling to clean up the disparity map * \param disparity_space array used for the disparity space * \param disparity_map returned disparity map */ void stereodense::update_disparity_map( unsigned char* img_left, unsigned char* img_right, int img_width, int img_height, int offset_x, int offset_y, int vertical_sampling, int max_disparity_percent, int correlation_radius, int smoothing_radius, int disparity_step, int disparity_threshold_percent, bool despeckle, int cross_checking_threshold, unsigned int *disparity_space, unsigned int *disparity_map) { int disparity_space_width = img_width/smoothing_radius; int disparity_space_height = (img_height / vertical_sampling)/STEREO_DENSE_SMOOTH_VERTICAL; int max_disparity_pixels = max_disparity_percent * img_width / 100; // correct the colours of the right image so that they're similar to the left colour_correction( img_left, img_right, img_width, img_height, offset_y); // create the disparity space update_disparity_space( img_left, img_right, img_width, img_height, offset_x, offset_y, vertical_sampling, max_disparity_percent, correlation_radius, smoothing_radius, disparity_step, disparity_space_width, disparity_space_height, disparity_space); // create the disparity map disparity_map_from_disparity_space( img_left, img_right, img_width, img_height, offset_x, offset_y, smoothing_radius, vertical_sampling, disparity_space, disparity_space_width, disparity_space_height, disparity_step, max_disparity_pixels/disparity_step, cross_checking_threshold, disparity_map); // optionally apply a threshold to the disparity map if (disparity_threshold_percent > 0) { unsigned int disparity_threshold_pixels = (unsigned int)(disparity_threshold_percent * max_disparity_pixels / 100); for (int i = disparity_space_width*disparity_space_height*2-2; i >= 0; i -= 2) { if (disparity_map[i+1] < disparity_threshold_pixels) { disparity_map[i+1] = 0; } } } // clean up the disparity map if (despeckle) { int pass = 0; while (despeckle_disparity_map( disparity_space_width, disparity_space_height, disparity_map, max_disparity_pixels)) { pass++; if (pass > 5) break; } if (disparity_threshold_percent > 0) { post_threshold_filter(disparity_map, disparity_space_width, disparity_space_height, 6); } } // multiply disparity values so that sub-pixel interpolation is possible for (int i = disparity_space_width*disparity_space_height*2-2; i >= 0; i -= 2) { disparity_map[i + 1] *= STEREO_DENSE_SUB_PIXEL; } }