"Cable", "Classroom1", "Couch", "Flowers", "Mask", "Shopvac",
"Sticks", "Storage", "Sword1", "Sword2", "Umbrella" };
+enum DistanceMode { DISTANCE_DEPTH, DISTANCE_DISPARITY };
+
class StopWatch
{
public:
std::string datasetName;
float minDisp;
float maxDisp;
+ float depth2Disp;
int fmt;
std::string dataset;
+ DistanceMode distanceMode;
} appdata;
enum
return uval[0] == 1;
}
-static void WriteFilePFM(float *data, int width, int height, const char *filename, float minDisp, float maxDisp,
- float scalefactor = 1 / 255.0)
+static void WriteFilePFM(unsigned short *data, int width, int height, const char *filename, float minDisp, float maxDisp,
+ float depth2Disp, DistanceMode distanceMode, float scalefactor = 1 / 255.0)
{
FILE *stream = fopen(filename, "wb");
if (stream == 0) {
fprintf(stream, "Pf\n%d %d\n%f\n", width, height, scalefactor);
- int n = width;
+ std::vector<float> dump(width);
for (int y = height - 1; y >= 0; y--) {
- float *ptr = data + y * width;
+ unsigned short* ptr = data + y * width;
for (int x = 0; x < width; x++) {
- if (ptr[x] <= 0 || ptr[x] > maxDisp) { //xsh modified
- ptr[x] = INFINITY;
- }
+ if (distanceMode == DISTANCE_DISPARITY)
+ dump[x] = depth2Disp / static_cast<float>(ptr[x]);
+ else
+ dump[x] = static_cast<float>(ptr[x]);
}
- if ((int) fwrite(ptr, sizeof(float), n, stream) != n) {
+ if ((int)fwrite(dump.data(), sizeof(float), width, stream) != width) {
fprintf(stderr, "WriteFilePFM: problem writing data\n");
exit(1);
}
}
+
fclose(stream);
}
}
static void WriteFilePNG(unsigned short *data, int width, int height, const char *filename, float minDisp,
- float maxDisp)
+ float maxDisp, float depth2Disp, int distanceMode)
{
// Open the file
FILE *stream = fopen(filename, "wb");
cv::Mat dump(cv::Size(width, height), CV_16U);
for (int y = 0; y < height; y++) {
- unsigned short *ptr = data + y * width;
+ unsigned short* ptr = data + y * width;
for (int x = 0; x < width; x++) {
- unsigned short f = ptr[x];
- dump.at<unsigned short>(y, x) = f;
+ if (distanceMode == DISTANCE_DISPARITY)
+ dump.at<unsigned short>(y,x) = static_cast<unsigned short>(depth2Disp / static_cast<float>(ptr[x]));
+ else
+ dump.at<unsigned short>(y,x) = ptr[x];
}
- }
+ }
- printf("%d x %d", width, height);
cv::imwrite(filename, dump);
fclose(stream);
StopWatch stopWatch;
if (udata->fmt == FMT_PFM) {
- WriteFilePFM(reinterpret_cast<float *>(depth), width, height, udata->datasetName.c_str(), udata->minDisp,
- udata->maxDisp);
+ WriteFilePFM(depth, width, height, udata->datasetName.c_str(),
+ udata->minDisp, udata->maxDisp, udata->depth2Disp, udata->distanceMode);
} else {
- WriteFilePNG(depth, width, height, udata->datasetName.c_str(), udata->minDisp, udata->maxDisp);
+ WriteFilePNG(depth, width, height, udata->datasetName.c_str(),
+ udata->minDisp, udata->maxDisp, udata->depth2Disp, udata->distanceMode);
}
udata->diffMs = stopWatch.elapsedTime();
sel_fmt = show_menu_linear("Select Action", formats, ARRAY_SIZE(formats));
}
+ const char* distances[] = {"disparty", "depth"};
+ int sel_distance = -1;
+ while (sel_distance <= 0 || sel_distance > ARRAY_SIZE(distances)) {
+ sel_distance = show_menu_linear("Select Action", distances, ARRAY_SIZE(distances));
+ }
+
err = mv_create_engine_config(&engine_config);
if (err != MEDIA_VISION_ERROR_NONE) {
printf("Failed to create engine config\n");
float fVal;
float dmin = 0, dmax = 0;
int iVal;
+ float fx = 0.f;
+ float baseline = 0.0f;
int width = 0, height = 0;
+
if (fp != NULL) {
while (fgets(line, MAX_STRING_LENGTH, fp) != NULL) {
if (sscanf(line, "vmin= %f", &fVal) == 1)
width = iVal;
if (sscanf(line, "height= %d", &iVal) == 1)
height = iVal;
+ if (sscanf(line, "cam0=[ %f", &fVal) == 1)
+ fx = fVal;
+ if (sscanf(line, "baseline= %f", &fVal) == 1)
+ baseline = fVal;
}
fclose(fp);
} else {
}
// left_source, right_source
- left_frame = cv::imread(leftFilename, cv::IMREAD_COLOR);
- right_frame = cv::imread(rightFilename, cv::IMREAD_COLOR);
+ left_frame = cv::imread(leftFilename, cv::IMREAD_GRAYSCALE);
+ right_frame = cv::imread(rightFilename, cv::IMREAD_GRAYSCALE);
err = mv_source_fill_by_buffer(left_source, left_frame.ptr<unsigned char>(),
left_frame.elemSize() * left_frame.size().width * left_frame.size().height,
left_frame.size().width, left_frame.size().height,
- MEDIA_VISION_COLORSPACE_RGB888);
+ MEDIA_VISION_COLORSPACE_Y800);
if (err != MEDIA_VISION_ERROR_NONE) {
printf("Failed to fill left_source\n");
goto _err;
err = mv_source_fill_by_buffer(right_source, right_frame.ptr<unsigned char>(),
right_frame.elemSize() * right_frame.size().width * right_frame.size().height,
right_frame.size().width, right_frame.size().height,
- MEDIA_VISION_COLORSPACE_RGB888);
+ MEDIA_VISION_COLORSPACE_Y800);
if (err != MEDIA_VISION_ERROR_NONE) {
printf("Failed to fill right_source\n");
goto _err;
std::string(dataPath) + std::string("/disp0") + std::string(suffix_for_algo),
static_cast<float>(minDisp),
static_cast<float>(maxDisp),
+ fx * baseline,
sel_fmt,
- std::string(dataset[data]) };
+ std::string(dataset[data]),
+ static_cast<DistanceMode>(sel_distance) };
+ printf("fx:%f, baseline:%f, d2d: %f\n", fx, baseline, dump.depth2Disp);
dump.datasetName += sel_fmt == FMT_PFM ? std::string(".pfm") : std::string(".png");
err = mv_3d_set_depth_cb(mv3d_handle, _depth_middlebury_cb, static_cast<void *>(&dump));