Пример #1
0
int main(int argc, char *argv[])
{
    try {
	int argn = 1;
	if (argc > 1 && argv[1][0]=='-' && argv[1][1]=='q') {
	    verbose = 0;
	    argn++;
	}
	if (argn >= argc-3 && argn <= argc-2) {
	    char *flowname = argv[argn++];
	    char *outname = argv[argn++];
	    float maxmotion = argn < argc ? atof(argv[argn++]) : -1;
	    CFloatImage im, fband;
	    ReadFlowFile(im, flowname);
	    CByteImage band, outim;
	    CShape sh = im.Shape();
	    sh.nBands = 3;
	    outim.ReAllocate(sh);
	    outim.ClearPixels();
	    MotionToColor(im, outim, maxmotion);
	    WriteImageVerb(outim, outname, verbose);
	} else
	    throw CError(usage, argv[0]);
    }
    catch (CError &err) {
	fprintf(stderr, err.message);
	fprintf(stderr, "\n");
	return -1;
    }

    return 0;
}
cv::Mat FlowIOOpenCVWrapper::read(std::string path) {
    
    CFloatImage flow;
    ReadFlowFile(flow, path.c_str());
    
    int rows = flow.Shape().height;
    int cols = flow.Shape().width;
    
    assert(rows > 0);
    assert(cols > 0);
    assert(flow.Shape().nBands == 2);
    
    cv::Mat matFlow(rows, cols, CV_32FC2, cv::Scalar(0, 0));
    
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            matFlow.at<cv::Vec2f>(i, j)[0] = flow.Pixel(j, i, 0);
            matFlow.at<cv::Vec2f>(i, j)[1] = flow.Pixel(j, i, 1);
        }
    }
    
    return matFlow;
}