Commit cdae0743 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

fix OpenGL render functions

fix createOpticalFlowNeedleMap
parent 70820224
......@@ -1330,7 +1330,7 @@ void cv::render(const GlArrays& arr, int mode, Scalar color)
#ifndef HAVE_OPENGL
throw_nogl;
#else
glColor3d(color[0] / 255.0, color[1] / 255.0, color[3] / 255.0);
glColor3d(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0);
arr.bind();
......@@ -1358,9 +1358,10 @@ void cv::render(const string& str, const Ptr<GlFont>& font, Scalar color, Point2
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3d(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0);
glRasterPos2d(2.0 * (viewport[0] + pos.x) / viewport[2] - 1.0, 1.0 - 2.0 * (viewport[1] + pos.y + font->height()) / viewport[3]);
glColor4dv(color.val);
font->draw(str.c_str(), str.length());
glPopAttrib();
......
......@@ -47,7 +47,6 @@ namespace cv { namespace gpu { namespace device
namespace optical_flow
{
#define NEEDLE_MAP_SCALE 16
#define MAX_FLOW 30.0f
#define NUM_VERTS_PER_ARROW 6
__global__ void NeedleMapAverageKernel(const DevMem2Df u, const PtrStepf v, PtrStepf u_avg, PtrStepf v_avg)
......@@ -123,7 +122,7 @@ namespace cv { namespace gpu { namespace device
cudaSafeCall( cudaDeviceSynchronize() );
}
__global__ void NeedleMapVertexKernel(const DevMem2Df u_avg, const PtrStepf v_avg, float* vertex_data, float* color_data, float xscale, float yscale)
__global__ void NeedleMapVertexKernel(const DevMem2Df u_avg, const PtrStepf v_avg, float* vertex_data, float* color_data, float max_flow, float xscale, float yscale)
{
// test - just draw a triangle at each pixel
const int x = blockIdx.x * blockDim.x + threadIdx.x;
......@@ -142,7 +141,7 @@ namespace cv { namespace gpu { namespace device
const float theta = ::atan2f(v_avg_val, u_avg_val) + CV_PI;
float r = ::sqrtf(v_avg_val * v_avg_val + u_avg_val * u_avg_val);
r = fmin(14.0f * (r / MAX_FLOW), 14.0f);
r = fmin(14.0f * (r / max_flow), 14.0f);
v[0].z = 1.0f;
v[1].z = 0.7f;
......@@ -203,12 +202,12 @@ namespace cv { namespace gpu { namespace device
}
}
void CreateOpticalFlowNeedleMap_gpu(DevMem2Df u_avg, DevMem2Df v_avg, float* vertex_buffer, float* color_data, float xscale, float yscale)
void CreateOpticalFlowNeedleMap_gpu(DevMem2Df u_avg, DevMem2Df v_avg, float* vertex_buffer, float* color_data, float max_flow, float xscale, float yscale)
{
const dim3 block(16);
const dim3 grid(divUp(u_avg.cols, block.x), divUp(u_avg.rows, block.y));
NeedleMapVertexKernel<<<grid, block>>>(u_avg, v_avg, vertex_buffer, color_data, xscale, yscale);
NeedleMapVertexKernel<<<grid, block>>>(u_avg, v_avg, vertex_buffer, color_data, max_flow, xscale, yscale);
cudaSafeCall( cudaGetLastError() );
cudaSafeCall( cudaDeviceSynchronize() );
......
......@@ -194,7 +194,7 @@ namespace cv { namespace gpu { namespace device
namespace optical_flow
{
void NeedleMapAverage_gpu(DevMem2Df u, DevMem2Df v, DevMem2Df u_avg, DevMem2Df v_avg);
void CreateOpticalFlowNeedleMap_gpu(DevMem2Df u_avg, DevMem2Df v_avg, float* vertex_buffer, float* color_data, float xscale, float yscale);
void CreateOpticalFlowNeedleMap_gpu(DevMem2Df u_avg, DevMem2Df v_avg, float* vertex_buffer, float* color_data, float max_flow, float xscale, float yscale);
}
}}}
......@@ -224,7 +224,13 @@ void cv::gpu::createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMa
colors.setTo(Scalar::all(1.0));
CreateOpticalFlowNeedleMap_gpu(u_avg, v_avg, vertex.ptr<float>(), colors.ptr<float>(), 1.0f / u.cols, 1.0f / u.rows);
double uMax, vMax;
minMax(u_avg, 0, &uMax);
minMax(v_avg, 0, &vMax);
float max_flow = static_cast<float>(sqrt(uMax * uMax + vMax * vMax));
CreateOpticalFlowNeedleMap_gpu(u_avg, v_avg, vertex.ptr<float>(), colors.ptr<float>(), max_flow, 1.0f / u.cols, 1.0f / u.rows);
cvtColor(colors, colors, COLOR_HSV2RGB);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment