Commit 07744af7 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #3066 from vpisarev:minor_fixes

parents 0f66e275 68305703
...@@ -297,7 +297,12 @@ static void update_warping_matrix_ECC (Mat& map_matrix, const Mat& update, const ...@@ -297,7 +297,12 @@ static void update_warping_matrix_ECC (Mat& map_matrix, const Mat& update, const
mapPtr[5] += updatePtr[7]; mapPtr[5] += updatePtr[7];
} }
if (motionType == MOTION_EUCLIDEAN) { if (motionType == MOTION_EUCLIDEAN) {
double new_theta = acos(mapPtr[0]) + updatePtr[0]; double new_theta = updatePtr[0];
if (mapPtr[3]>0)
new_theta += acos(mapPtr[0]);
if (mapPtr[3]<0)
new_theta -= acos(mapPtr[0]);
mapPtr[2] += updatePtr[1]; mapPtr[2] += updatePtr[1];
mapPtr[5] += updatePtr[2]; mapPtr[5] += updatePtr[2];
......
...@@ -43,6 +43,10 @@ ...@@ -43,6 +43,10 @@
#include "precomp.hpp" #include "precomp.hpp"
#include "opencl_kernels_video.hpp" #include "opencl_kernels_video.hpp"
#if defined __APPLE__ || defined ANDROID
#define SMALL_LOCALSIZE
#endif
// //
// 2D dense optical flow algorithm from the following paper: // 2D dense optical flow algorithm from the following paper:
// Gunnar Farneback. "Two-Frame Motion Estimation Based on Polynomial Expansion". // Gunnar Farneback. "Two-Frame Motion Estimation Based on Polynomial Expansion".
...@@ -836,7 +840,7 @@ private: ...@@ -836,7 +840,7 @@ private:
bool gaussianBlurOcl(const UMat &src, int ksizeHalf, UMat &dst) bool gaussianBlurOcl(const UMat &src, int ksizeHalf, UMat &dst)
{ {
#ifdef ANDROID #ifdef SMALL_LOCALSIZE
size_t localsize[2] = { 128, 1}; size_t localsize[2] = { 128, 1};
#else #else
size_t localsize[2] = { 256, 1}; size_t localsize[2] = { 256, 1};
...@@ -863,7 +867,7 @@ private: ...@@ -863,7 +867,7 @@ private:
bool gaussianBlur5Ocl(const UMat &src, int ksizeHalf, UMat &dst) bool gaussianBlur5Ocl(const UMat &src, int ksizeHalf, UMat &dst)
{ {
int height = src.rows / 5; int height = src.rows / 5;
#ifdef ANDROID #ifdef SMALL_LOCALSIZE
size_t localsize[2] = { 128, 1}; size_t localsize[2] = { 128, 1};
#else #else
size_t localsize[2] = { 256, 1}; size_t localsize[2] = { 256, 1};
...@@ -888,7 +892,7 @@ private: ...@@ -888,7 +892,7 @@ private:
} }
bool polynomialExpansionOcl(const UMat &src, UMat &dst) bool polynomialExpansionOcl(const UMat &src, UMat &dst)
{ {
#ifdef ANDROID #ifdef SMALL_LOCALSIZE
size_t localsize[2] = { 128, 1}; size_t localsize[2] = { 128, 1};
#else #else
size_t localsize[2] = { 256, 1}; size_t localsize[2] = { 256, 1};
...@@ -925,7 +929,7 @@ private: ...@@ -925,7 +929,7 @@ private:
bool boxFilter5Ocl(const UMat &src, int ksizeHalf, UMat &dst) bool boxFilter5Ocl(const UMat &src, int ksizeHalf, UMat &dst)
{ {
int height = src.rows / 5; int height = src.rows / 5;
#ifdef ANDROID #ifdef SMALL_LOCALSIZE
size_t localsize[2] = { 128, 1}; size_t localsize[2] = { 128, 1};
#else #else
size_t localsize[2] = { 256, 1}; size_t localsize[2] = { 256, 1};
...@@ -952,7 +956,7 @@ private: ...@@ -952,7 +956,7 @@ private:
bool updateFlowOcl(const UMat &M, UMat &flowx, UMat &flowy) bool updateFlowOcl(const UMat &M, UMat &flowx, UMat &flowy)
{ {
#ifdef ANDROID #ifdef SMALL_LOCALSIZE
size_t localsize[2] = { 32, 4}; size_t localsize[2] = { 32, 4};
#else #else
size_t localsize[2] = { 32, 8}; size_t localsize[2] = { 32, 8};
...@@ -976,7 +980,7 @@ private: ...@@ -976,7 +980,7 @@ private:
} }
bool updateMatricesOcl(const UMat &flowx, const UMat &flowy, const UMat &R0, const UMat &R1, UMat &M) bool updateMatricesOcl(const UMat &flowx, const UMat &flowy, const UMat &R0, const UMat &R1, UMat &M)
{ {
#ifdef ANDROID #ifdef SMALL_LOCALSIZE
size_t localsize[2] = { 32, 4}; size_t localsize[2] = { 32, 4};
#else #else
size_t localsize[2] = { 32, 8}; size_t localsize[2] = { 32, 8};
......
...@@ -37,7 +37,8 @@ int main(int, char**) ...@@ -37,7 +37,8 @@ int main(int, char**)
if( !cap.isOpened() ) if( !cap.isOpened() )
return -1; return -1;
Mat prevgray, gray, flow, cflow, frame; Mat flow, cflow, frame;
UMat gray, prevgray, uflow;
namedWindow("flow", 1); namedWindow("flow", 1);
for(;;) for(;;)
...@@ -45,10 +46,11 @@ int main(int, char**) ...@@ -45,10 +46,11 @@ int main(int, char**)
cap >> frame; cap >> frame;
cvtColor(frame, gray, COLOR_BGR2GRAY); cvtColor(frame, gray, COLOR_BGR2GRAY);
if( prevgray.data ) if( !prevgray.empty() )
{ {
calcOpticalFlowFarneback(prevgray, gray, flow, 0.5, 3, 15, 3, 5, 1.2, 0); calcOpticalFlowFarneback(prevgray, gray, uflow, 0.5, 3, 15, 3, 5, 1.2, 0);
cvtColor(prevgray, cflow, COLOR_GRAY2BGR); cvtColor(prevgray, cflow, COLOR_GRAY2BGR);
uflow.copyTo(flow);
drawOptFlowMap(flow, cflow, 16, 1.5, Scalar(0, 255, 0)); drawOptFlowMap(flow, cflow, 16, 1.5, Scalar(0, 255, 0));
imshow("flow", cflow); imshow("flow", cflow);
} }
......
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