介绍
将稠密光流场按照孟塞尔颜色体系(Munsell Color System)转化为RBG图,这个其实没什么卵用,只不过是开发光流估计算法或者光流应用时提供一种结果可视化的途径。
实现过程时参照python版本的flownet2提供的代码。
需要注意的是不要用unsigned char 类型的变量存储数值变量,我用一天的时间才把这个bug修复
flo2img_tmp.hpp
#ifndef FLO2IMGTMP_HPP_
#define FLO2IMGTMP_HPP_
#ifdef USE_OPENCV
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif // USE_OPENCV
//typedef unsigned short UINT;
class Flo2Img {
public:
Flo2Img();
private:
unsigned short colorwheel[55][3];
unsigned short ncols;
};
void flo2img(cv::Mat& flo, cv::Mat &img);
#endif
flo2img_tmp.cpp
#ifdef USE_OPENCV
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif // USE_OPENCV
#include <flo2img_tmp.hpp>
#include <iostream>
#include "math.h"
#define UNKNOWN_THRESH 1e5
#define EPS 1e-10
#define pi 3.1415926
void flo2img(cv::Mat& flo, cv::Mat& img)
{
unsigned char ncols;
unsigned short RY = 15;
unsigned short YG = 6;
unsigned short GC = 4;
unsigned short CB = 11;
unsigned short BM = 13;
unsigned short MR = 6;
ncols = RY + YG + GC + CB + BM + MR;
float colorwheel[55][3];
unsigned short nchans = 3;
unsigned short col = 0;
//RY
for (int i = 0; i<RY; i++)
{
colorwheel[col + i][0] = 255;
colorwheel[col + i][1] = 255 * i / RY;
colorwheel[col + i][2] = 0;
//std::cout << colorwheel[i][1] << '\n';
}
col += RY;
//YG
for (int i = 0; i<YG; i++)
{
colorwheel[col + i][0] = 255 - 255 * i / YG;
colorwheel[col + i][1] = 255;
colorwheel[col + i][2] = 0;
}
col += YG;
//GC
for (int i = 0; i < GC; i++)
{
colorwheel[col + i][1] = 255;
colorwheel[col + i][2] = 255 * i / GC;
colorwheel[col + i][0] = 0;
}
col += GC;
//CB
for (int i = 0; i < CB; i++)
{
colorwheel[col + i][1] = 255 - 255 * i / CB;
colorwheel[col + i][2] = 255;
colorwheel[col + i][0] = 0;
}
col += CB;
//BM
for (int i = 0; i < BM; i++)
{
colorwheel[col + i][2] = 255;
colorwheel[col + i][0] = 255 * i / BM;
colorwheel[col + i][1] = 0;
}
col += BM;
//MR
for (int i = 0; i < MR; i++)
{
colorwheel[col + i][2] = 255 - 255 * i / MR;
colorwheel[col + i][0] = 255;
colorwheel[col