Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void VD5(){
- for (int img = 0; img < 200; img++)
- {
- std::string name("flow/u");
- if (img < 10){ name += "0000"; }
- else if (img < 100){ name += "000"; }
- else{ name += "00"; }
- name += to_string(img);
- name += ".yml";
- FileStorage fs2(name, FileStorage::READ);
- Mat flow;
- fs2["flow"] >> flow;
- int bigger = 5;
- Mat data = Mat(flow.rows, flow.cols, CV_32FC1);
- Mat data2 = Mat::zeros(flow.rows, flow.cols, CV_8UC3);
- Mat lines = Mat::zeros(flow.rows*bigger, flow.cols * bigger, CV_8UC3);
- Mat directions = Mat::zeros(flow.rows, flow.cols, CV_32FC2);
- float max = 0;
- float min = 99;
- float deltat = 0.7f;
- for (int r = 0; r < flow.rows; r++)
- {
- for (int c = 0; c < flow.cols; c++)
- {
- data.at<float>(r, c) = sqrt(SQR(flow.at<cv::Vec2f>(r, c)[1]) + SQR(flow.at<cv::Vec2f>(r, c)[0]));
- if (max < data.at<float>(r, c)){
- max = data.at<float>(r, c);
- }
- if (min > data.at<float>(r, c)){
- min = data.at<float>(r, c);
- }
- //cout << flow.at<cv::Vec2f>(r, c)[0]<< " " << flow.at<cv::Vec2f>(r, c)[1] << endl;
- directions.at<cv::Vec2f>(r, c) = Vec2f(r + (flow.at<cv::Vec2f>(r, c)[1] * deltat), c + (flow.at<cv::Vec2f>(r, c)[0] * deltat));
- data2.at<Vec3b>(r, c) = ColorRamp(data.at<float>(r, c), 0, 6.5, color_scale_ramp, color_scale_ramp_size);
- }
- }
- int step = 4;
- for (int r = 0; r < flow.rows; r+=step)
- {
- for (int c = 0; c < flow.cols; c += step)
- {
- //lines.at<Vec3b>(r * bigger, c * bigger) = ColorRamp(flow.at<cv::Vec2f>(r, c)[0], -2.7, 2.0, color_scale_ramp, color_scale_ramp_size);
- line(lines,
- Point(c* bigger, r * bigger),
- Point(directions.at<cv::Vec2f>(r, c)[1] * bigger, directions.at<cv::Vec2f>(r, c)[0] * bigger),
- //Scalar(ColorRamp(flow.at<cv::Vec2f>(r, c)[1], -6.7, 1.0, color_scale_ramp, color_scale_ramp_size)),
- Scalar(ColorRamp(data.at<float>(r, c), 0, 6.5, color_scale_ramp, color_scale_ramp_size)),
- 1);
- }
- }
- //cout << max <<" "<<min<< endl;
- resize(data2, data2, Size(500, 500));
- //resize(lines, lines, Size(500, 500));
- imshow("test", data2);
- imshow("lines", lines);
- waitKey(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement