mirror of https://github.com/opencv/opencv.git
Merge pull request #1046 from SpecLad:merge-2.4
commit
89086bdb8d
46 changed files with 2658 additions and 1802 deletions
@ -1,180 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Jia Haipeng, jiahaipeng95@gmail.com
|
||||
// Sen Liu, swjutls1987@126.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other oclMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "opencv2/objdetect.hpp" |
||||
#include "precomp.hpp" |
||||
|
||||
#if 0 //def HAVE_OPENCL
|
||||
|
||||
using namespace cvtest; |
||||
using namespace testing; |
||||
using namespace std; |
||||
using namespace cv; |
||||
extern string workdir; |
||||
|
||||
namespace |
||||
{ |
||||
IMPLEMENT_PARAM_CLASS(CascadeName, std::string); |
||||
CascadeName cascade_frontalface_alt(std::string("haarcascade_frontalface_alt.xml")); |
||||
CascadeName cascade_frontalface_alt2(std::string("haarcascade_frontalface_alt2.xml")); |
||||
struct getRect |
||||
{ |
||||
Rect operator ()(const CvAvgComp &e) const |
||||
{ |
||||
return e.rect; |
||||
} |
||||
}; |
||||
} |
||||
|
||||
PARAM_TEST_CASE(Haar, double, int, CascadeName) |
||||
{ |
||||
cv::ocl::OclCascadeClassifier cascade, nestedCascade; |
||||
cv::CascadeClassifier cpucascade, cpunestedCascade; |
||||
|
||||
double scale; |
||||
int flags; |
||||
std::string cascadeName; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
scale = GET_PARAM(0); |
||||
flags = GET_PARAM(1); |
||||
cascadeName = (workdir + "../../data/haarcascades/").append(GET_PARAM(2)); |
||||
|
||||
if( (!cascade.load( cascadeName )) || (!cpucascade.load(cascadeName)) ) |
||||
{ |
||||
cout << "ERROR: Could not load classifier cascade" << endl; |
||||
return; |
||||
} |
||||
} |
||||
}; |
||||
|
||||
////////////////////////////////faceDetect/////////////////////////////////////////////////
|
||||
TEST_P(Haar, FaceDetect) |
||||
{ |
||||
string imgName = workdir + "lena.jpg"; |
||||
Mat img = imread( imgName, 1 ); |
||||
|
||||
if(img.empty()) |
||||
{ |
||||
std::cout << "Couldn't read " << imgName << std::endl; |
||||
return ; |
||||
} |
||||
|
||||
vector<Rect> faces, oclfaces; |
||||
|
||||
Mat gray, smallImg(cvRound (img.rows / scale), cvRound(img.cols / scale), CV_8UC1 ); |
||||
MemStorage storage(cvCreateMemStorage(0)); |
||||
cvtColor( img, gray, COLOR_BGR2GRAY ); |
||||
resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR ); |
||||
equalizeHist( smallImg, smallImg ); |
||||
|
||||
cv::ocl::oclMat image; |
||||
CvSeq *_objects; |
||||
image.upload(smallImg); |
||||
_objects = cascade.oclHaarDetectObjects( image, storage, 1.1, |
||||
3, flags, Size(30, 30), Size(0, 0) ); |
||||
vector<CvAvgComp> vecAvgComp; |
||||
Seq<CvAvgComp>(_objects).copyTo(vecAvgComp); |
||||
oclfaces.resize(vecAvgComp.size()); |
||||
std::transform(vecAvgComp.begin(), vecAvgComp.end(), oclfaces.begin(), getRect()); |
||||
|
||||
cpucascade.detectMultiScale( smallImg, faces, 1.1, 3, |
||||
flags, |
||||
Size(30, 30), Size(0, 0) ); |
||||
EXPECT_EQ(faces.size(), oclfaces.size()); |
||||
} |
||||
|
||||
TEST_P(Haar, FaceDetectUseBuf) |
||||
{ |
||||
string imgName = workdir + "lena.jpg"; |
||||
Mat img = imread( imgName, 1 ); |
||||
|
||||
if(img.empty()) |
||||
{ |
||||
std::cout << "Couldn't read " << imgName << std::endl; |
||||
return ; |
||||
} |
||||
|
||||
vector<Rect> faces, oclfaces; |
||||
|
||||
Mat gray, smallImg(cvRound (img.rows / scale), cvRound(img.cols / scale), CV_8UC1 ); |
||||
cvtColor( img, gray, CV_BGR2GRAY ); |
||||
resize( gray, smallImg, smallImg.size(), 0, 0, INTER_LINEAR ); |
||||
equalizeHist( smallImg, smallImg ); |
||||
|
||||
cv::ocl::oclMat image; |
||||
image.upload(smallImg); |
||||
|
||||
cv::ocl::OclCascadeClassifierBuf cascadebuf; |
||||
if( !cascadebuf.load( cascadeName ) ) |
||||
{ |
||||
cout << "ERROR: Could not load classifier cascade for FaceDetectUseBuf!" << endl; |
||||
return; |
||||
} |
||||
cascadebuf.detectMultiScale( image, oclfaces, 1.1, 3, |
||||
flags, |
||||
Size(30, 30), Size(0, 0) ); |
||||
|
||||
cpucascade.detectMultiScale( smallImg, faces, 1.1, 3, |
||||
flags, |
||||
Size(30, 30), Size(0, 0) ); |
||||
EXPECT_EQ(faces.size(), oclfaces.size()); |
||||
|
||||
// intentionally run ocl facedetect again and check if it still works after the first run
|
||||
cascadebuf.detectMultiScale( image, oclfaces, 1.1, 3, |
||||
flags, |
||||
Size(30, 30)); |
||||
cascadebuf.release(); |
||||
EXPECT_EQ(faces.size(), oclfaces.size()); |
||||
} |
||||
|
||||
INSTANTIATE_TEST_CASE_P(FaceDetect, Haar, |
||||
Combine(Values(1.0), |
||||
Values(CV_HAAR_SCALE_IMAGE, 0), Values(cascade_frontalface_alt, cascade_frontalface_alt2))); |
||||
|
||||
#endif // HAVE_OPENCL
|
@ -1,90 +0,0 @@ |
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
|
||||
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// @Authors
|
||||
// Zhang Chunpeng chunpeng@multicorewareinc.com
|
||||
// Yao Wang yao@multicorewareinc.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other oclMaterials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp" |
||||
|
||||
#ifdef HAVE_OPENCL |
||||
|
||||
using namespace cv; |
||||
using namespace cvtest; |
||||
using namespace testing; |
||||
using namespace std; |
||||
|
||||
PARAM_TEST_CASE(PyrUp, MatType, int) |
||||
{ |
||||
int type; |
||||
int channels; |
||||
|
||||
virtual void SetUp() |
||||
{ |
||||
type = GET_PARAM(0); |
||||
channels = GET_PARAM(1); |
||||
} |
||||
}; |
||||
|
||||
TEST_P(PyrUp, Accuracy) |
||||
{ |
||||
for(int j = 0; j < LOOP_TIMES; j++) |
||||
{ |
||||
Size size(MWIDTH, MHEIGHT); |
||||
Mat src = randomMat(size, CV_MAKETYPE(type, channels)); |
||||
Mat dst_gold; |
||||
pyrUp(src, dst_gold); |
||||
ocl::oclMat dst; |
||||
ocl::oclMat srcMat(src); |
||||
ocl::pyrUp(srcMat, dst); |
||||
|
||||
EXPECT_MAT_NEAR(dst_gold, Mat(dst), (type == CV_32F ? 1e-4f : 1.0)); |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(OCL_ImgProc, PyrUp, testing::Combine( |
||||
Values(CV_8U, CV_32F), Values(1, 3, 4))); |
||||
|
||||
|
||||
#endif // HAVE_OPENCL
|
@ -0,0 +1,167 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
from __future__ import division |
||||
|
||||
import ast |
||||
import logging |
||||
import numbers |
||||
import os, os.path |
||||
import re |
||||
|
||||
from argparse import ArgumentParser |
||||
from collections import OrderedDict |
||||
from glob import glob |
||||
from itertools import ifilter |
||||
|
||||
import xlwt |
||||
|
||||
from testlog_parser import parseLogFile |
||||
|
||||
# To build XLS report you neet to put your xmls (OpenCV tests output) in the |
||||
# following way: |
||||
# |
||||
# "root" --- folder, representing the whole XLS document. It contains several |
||||
# subfolders --- sheet-paths of the XLS document. Each sheet-path contains it's |
||||
# subfolders --- config-paths. Config-paths are columns of the sheet and |
||||
# they contains xmls files --- output of OpenCV modules testing. |
||||
# Config-path means OpenCV build configuration, including different |
||||
# options such as NEON, TBB, GPU enabling/disabling. |
||||
# |
||||
# root |
||||
# root\sheet_path |
||||
# root\sheet_path\configuration1 (column 1) |
||||
# root\sheet_path\configuration2 (column 2) |
||||
|
||||
re_image_size = re.compile(r'^ \d+ x \d+$', re.VERBOSE) |
||||
re_data_type = re.compile(r'^ (?: 8 | 16 | 32 | 64 ) [USF] C [1234] $', re.VERBOSE) |
||||
|
||||
time_style = xlwt.easyxf(num_format_str='#0.00') |
||||
no_time_style = xlwt.easyxf('pattern: pattern solid, fore_color gray25') |
||||
|
||||
speedup_style = time_style |
||||
good_speedup_style = xlwt.easyxf('font: color green', num_format_str='#0.00') |
||||
bad_speedup_style = xlwt.easyxf('font: color red', num_format_str='#0.00') |
||||
no_speedup_style = no_time_style |
||||
error_speedup_style = xlwt.easyxf('pattern: pattern solid, fore_color orange') |
||||
header_style = xlwt.easyxf('font: bold true; alignment: horizontal centre, vertical top, wrap True') |
||||
|
||||
def collect_xml(collection, configuration, xml_fullname): |
||||
xml_fname = os.path.split(xml_fullname)[1] |
||||
module = xml_fname[:xml_fname.index('_')] |
||||
|
||||
module_tests = collection.setdefault(module, OrderedDict()) |
||||
|
||||
for test in sorted(parseLogFile(xml_fullname)): |
||||
test_results = module_tests.setdefault((test.shortName(), test.param()), {}) |
||||
test_results[configuration] = test.get("gmean") if test.status == 'run' else test.status |
||||
|
||||
def main(): |
||||
arg_parser = ArgumentParser(description='Build an XLS performance report.') |
||||
arg_parser.add_argument('sheet_dirs', nargs='+', metavar='DIR', help='directory containing perf test logs') |
||||
arg_parser.add_argument('-o', '--output', metavar='XLS', default='report.xls', help='name of output file') |
||||
arg_parser.add_argument('-c', '--config', metavar='CONF', help='global configuration file') |
||||
|
||||
args = arg_parser.parse_args() |
||||
|
||||
logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) |
||||
|
||||
if args.config is not None: |
||||
with open(args.config) as global_conf_file: |
||||
global_conf = ast.literal_eval(global_conf_file.read()) |
||||
else: |
||||
global_conf = {} |
||||
|
||||
wb = xlwt.Workbook() |
||||
|
||||
for sheet_path in args.sheet_dirs: |
||||
try: |
||||
with open(os.path.join(sheet_path, 'sheet.conf')) as sheet_conf_file: |
||||
sheet_conf = ast.literal_eval(sheet_conf_file.read()) |
||||
except Exception: |
||||
sheet_conf = {} |
||||
logging.debug('no sheet.conf for %s', sheet_path) |
||||
|
||||
sheet_conf = dict(global_conf.items() + sheet_conf.items()) |
||||
|
||||
if 'configurations' in sheet_conf: |
||||
config_names = sheet_conf['configurations'] |
||||
else: |
||||
try: |
||||
config_names = [p for p in os.listdir(sheet_path) |
||||
if os.path.isdir(os.path.join(sheet_path, p))] |
||||
except Exception as e: |
||||
logging.warning('error while determining configuration names for %s: %s', sheet_path, e) |
||||
continue |
||||
|
||||
collection = {} |
||||
|
||||
for configuration, configuration_path in \ |
||||
[(c, os.path.join(sheet_path, c)) for c in config_names]: |
||||
logging.info('processing %s', configuration_path) |
||||
for xml_fullname in glob(os.path.join(configuration_path, '*.xml')): |
||||
collect_xml(collection, configuration, xml_fullname) |
||||
|
||||
sheet = wb.add_sheet(sheet_conf.get('sheet_name', os.path.basename(os.path.abspath(sheet_path)))) |
||||
|
||||
sheet.row(0).height = 800 |
||||
sheet.panes_frozen = True |
||||
sheet.remove_splits = True |
||||
sheet.horz_split_pos = 1 |
||||
sheet.horz_split_first_visible = 1 |
||||
|
||||
sheet_comparisons = sheet_conf.get('comparisons', []) |
||||
|
||||
for i, w in enumerate([2000, 15000, 2500, 2000, 15000] |
||||
+ (len(config_names) + 1 + len(sheet_comparisons)) * [3000]): |
||||
sheet.col(i).width = w |
||||
|
||||
for i, caption in enumerate(['Module', 'Test', 'Image\nsize', 'Data\ntype', 'Parameters'] |
||||
+ config_names + [None] |
||||
+ [comp['to'] + '\nvs\n' + comp['from'] for comp in sheet_comparisons]): |
||||
sheet.row(0).write(i, caption, header_style) |
||||
|
||||
row = 1 |
||||
|
||||
module_colors = sheet_conf.get('module_colors', {}) |
||||
module_styles = {module: xlwt.easyxf('pattern: pattern solid, fore_color {}'.format(color)) |
||||
for module, color in module_colors.iteritems()} |
||||
|
||||
for module, tests in sorted(collection.iteritems()): |
||||
for ((test, param), configs) in tests.iteritems(): |
||||
sheet.write(row, 0, module, module_styles.get(module, xlwt.Style.default_style)) |
||||
sheet.write(row, 1, test) |
||||
|
||||
param_list = param[1:-1].split(", ") |
||||
sheet.write(row, 2, next(ifilter(re_image_size.match, param_list), None)) |
||||
sheet.write(row, 3, next(ifilter(re_data_type.match, param_list), None)) |
||||
|
||||
sheet.row(row).write(4, param) |
||||
for i, c in enumerate(config_names): |
||||
if c in configs: |
||||
sheet.write(row, 5 + i, configs[c], time_style) |
||||
else: |
||||
sheet.write(row, 5 + i, None, no_time_style) |
||||
|
||||
for i, comp in enumerate(sheet_comparisons): |
||||
cmp_from = configs.get(comp["from"]) |
||||
cmp_to = configs.get(comp["to"]) |
||||
col = 5 + len(config_names) + 1 + i |
||||
|
||||
if isinstance(cmp_from, numbers.Number) and isinstance(cmp_to, numbers.Number): |
||||
try: |
||||
speedup = cmp_from / cmp_to |
||||
sheet.write(row, col, speedup, good_speedup_style if speedup > 1.1 else |
||||
bad_speedup_style if speedup < 0.9 else |
||||
speedup_style) |
||||
except ArithmeticError as e: |
||||
sheet.write(row, col, None, error_speedup_style) |
||||
else: |
||||
sheet.write(row, col, None, no_speedup_style) |
||||
|
||||
row += 1 |
||||
if row % 1000 == 0: sheet.flush_row_data() |
||||
|
||||
wb.save(args.output) |
||||
|
||||
if __name__ == '__main__': |
||||
main() |
@ -0,0 +1,264 @@ |
||||
#include <iostream> |
||||
#include <vector> |
||||
#include <iomanip> |
||||
|
||||
#include "opencv2/core/utility.hpp" |
||||
#include "opencv2/highgui/highgui.hpp" |
||||
#include "opencv2/ocl/ocl.hpp" |
||||
#include "opencv2/video/video.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::ocl; |
||||
|
||||
typedef unsigned char uchar; |
||||
#define LOOP_NUM 10 |
||||
int64 work_begin = 0; |
||||
int64 work_end = 0; |
||||
|
||||
static void workBegin() |
||||
{ |
||||
work_begin = getTickCount(); |
||||
} |
||||
static void workEnd() |
||||
{ |
||||
work_end += (getTickCount() - work_begin); |
||||
} |
||||
static double getTime() |
||||
{ |
||||
return work_end * 1000. / getTickFrequency(); |
||||
} |
||||
|
||||
template <typename T> inline T clamp (T x, T a, T b) |
||||
{ |
||||
return ((x) > (a) ? ((x) < (b) ? (x) : (b)) : (a)); |
||||
} |
||||
|
||||
template <typename T> inline T mapValue(T x, T a, T b, T c, T d) |
||||
{ |
||||
x = clamp(x, a, b); |
||||
return c + (d - c) * (x - a) / (b - a); |
||||
} |
||||
|
||||
static void getFlowField(const Mat& u, const Mat& v, Mat& flowField) |
||||
{ |
||||
float maxDisplacement = 1.0f; |
||||
|
||||
for (int i = 0; i < u.rows; ++i) |
||||
{ |
||||
const float* ptr_u = u.ptr<float>(i); |
||||
const float* ptr_v = v.ptr<float>(i); |
||||
|
||||
for (int j = 0; j < u.cols; ++j) |
||||
{ |
||||
float d = max(fabsf(ptr_u[j]), fabsf(ptr_v[j])); |
||||
|
||||
if (d > maxDisplacement) |
||||
maxDisplacement = d; |
||||
} |
||||
} |
||||
|
||||
flowField.create(u.size(), CV_8UC4); |
||||
|
||||
for (int i = 0; i < flowField.rows; ++i) |
||||
{ |
||||
const float* ptr_u = u.ptr<float>(i); |
||||
const float* ptr_v = v.ptr<float>(i); |
||||
|
||||
|
||||
Vec4b* row = flowField.ptr<Vec4b>(i); |
||||
|
||||
for (int j = 0; j < flowField.cols; ++j) |
||||
{ |
||||
row[j][0] = 0; |
||||
row[j][1] = static_cast<unsigned char> (mapValue (-ptr_v[j], -maxDisplacement, maxDisplacement, 0.0f, 255.0f)); |
||||
row[j][2] = static_cast<unsigned char> (mapValue ( ptr_u[j], -maxDisplacement, maxDisplacement, 0.0f, 255.0f)); |
||||
row[j][3] = 255; |
||||
} |
||||
} |
||||
} |
||||
|
||||
|
||||
int main(int argc, const char* argv[]) |
||||
{ |
||||
static std::vector<Info> ocl_info; |
||||
ocl::getDevice(ocl_info); |
||||
//if you want to use undefault device, set it here
|
||||
setDevice(ocl_info[0]); |
||||
|
||||
//set this to save kernel compile time from second time you run
|
||||
ocl::setBinpath("./"); |
||||
const char* keys = |
||||
"{ h | help | false | print help message }" |
||||
"{ l | left | | specify left image }" |
||||
"{ r | right | | specify right image }" |
||||
"{ o | output | tvl1_output.jpg | specify output save path }" |
||||
"{ c | camera | 0 | enable camera capturing }" |
||||
"{ s | use_cpu | false | use cpu or gpu to process the image }" |
||||
"{ v | video | | use video as input }"; |
||||
|
||||
CommandLineParser cmd(argc, argv, keys); |
||||
|
||||
if (cmd.get<bool>("help")) |
||||
{ |
||||
cout << "Usage: pyrlk_optical_flow [options]" << endl; |
||||
cout << "Avaible options:" << endl; |
||||
cmd.printMessage(); |
||||
return 0; |
||||
} |
||||
|
||||
bool defaultPicturesFail = false; |
||||
string fname0 = cmd.get<string>("l"); |
||||
string fname1 = cmd.get<string>("r"); |
||||
string vdofile = cmd.get<string>("v"); |
||||
string outpath = cmd.get<string>("o"); |
||||
bool useCPU = cmd.get<bool>("s"); |
||||
bool useCamera = cmd.get<bool>("c"); |
||||
int inputName = cmd.get<int>("c"); |
||||
|
||||
Mat frame0 = imread(fname0, cv::IMREAD_GRAYSCALE); |
||||
Mat frame1 = imread(fname1, cv::IMREAD_GRAYSCALE); |
||||
cv::Ptr<cv::DenseOpticalFlow> alg = cv::createOptFlow_DualTVL1(); |
||||
cv::ocl::OpticalFlowDual_TVL1_OCL d_alg; |
||||
|
||||
|
||||
Mat flow, show_flow; |
||||
Mat flow_vec[2]; |
||||
if (frame0.empty() || frame1.empty()) |
||||
{ |
||||
useCamera = true; |
||||
defaultPicturesFail = true; |
||||
VideoCapture capture( inputName ); |
||||
if (!capture.isOpened()) |
||||
{ |
||||
cout << "Can't load input images" << endl; |
||||
return -1; |
||||
} |
||||
} |
||||
|
||||
|
||||
if (useCamera) |
||||
{ |
||||
VideoCapture capture; |
||||
Mat frame, frameCopy; |
||||
Mat frame0Gray, frame1Gray; |
||||
Mat ptr0, ptr1; |
||||
|
||||
if(vdofile == "") |
||||
capture.open( inputName ); |
||||
else |
||||
capture.open(vdofile.c_str()); |
||||
|
||||
int c = inputName ; |
||||
if(!capture.isOpened()) |
||||
{ |
||||
if(vdofile == "") |
||||
cout << "Capture from CAM " << c << " didn't work" << endl; |
||||
else |
||||
cout << "Capture from file " << vdofile << " failed" <<endl; |
||||
if (defaultPicturesFail) |
||||
{ |
||||
return -1; |
||||
} |
||||
goto nocamera; |
||||
} |
||||
|
||||
cout << "In capture ..." << endl; |
||||
for(int i = 0;; i++) |
||||
{ |
||||
if( !capture.read(frame) ) |
||||
break; |
||||
|
||||
if (i == 0) |
||||
{ |
||||
frame.copyTo( frame0 ); |
||||
cvtColor(frame0, frame0Gray, COLOR_BGR2GRAY); |
||||
} |
||||
else |
||||
{ |
||||
if (i%2 == 1) |
||||
{ |
||||
frame.copyTo(frame1); |
||||
cvtColor(frame1, frame1Gray, COLOR_BGR2GRAY); |
||||
ptr0 = frame0Gray; |
||||
ptr1 = frame1Gray; |
||||
} |
||||
else |
||||
{ |
||||
frame.copyTo(frame0); |
||||
cvtColor(frame0, frame0Gray, COLOR_BGR2GRAY); |
||||
ptr0 = frame1Gray; |
||||
ptr1 = frame0Gray; |
||||
} |
||||
|
||||
if (useCPU) |
||||
{ |
||||
alg->calc(ptr0, ptr1, flow); |
||||
split(flow, flow_vec); |
||||
} |
||||
else |
||||
{ |
||||
oclMat d_flowx, d_flowy; |
||||
d_alg(oclMat(ptr0), oclMat(ptr1), d_flowx, d_flowy); |
||||
d_flowx.download(flow_vec[0]); |
||||
d_flowy.download(flow_vec[1]); |
||||
} |
||||
if (i%2 == 1) |
||||
frame1.copyTo(frameCopy); |
||||
else |
||||
frame0.copyTo(frameCopy); |
||||
getFlowField(flow_vec[0], flow_vec[1], show_flow); |
||||
imshow("PyrLK [Sparse]", show_flow); |
||||
} |
||||
|
||||
if( waitKey( 10 ) >= 0 ) |
||||
goto _cleanup_; |
||||
} |
||||
|
||||
waitKey(0); |
||||
|
||||
_cleanup_: |
||||
capture.release(); |
||||
} |
||||
else |
||||
{ |
||||
nocamera: |
||||
oclMat d_flowx, d_flowy; |
||||
for(int i = 0; i <= LOOP_NUM; i ++) |
||||
{ |
||||
cout << "loop" << i << endl; |
||||
|
||||
if (i > 0) workBegin(); |
||||
if (useCPU) |
||||
{ |
||||
alg->calc(frame0, frame1, flow); |
||||
split(flow, flow_vec); |
||||
} |
||||
else |
||||
{ |
||||
d_alg(oclMat(frame0), oclMat(frame1), d_flowx, d_flowy); |
||||
d_flowx.download(flow_vec[0]); |
||||
d_flowy.download(flow_vec[1]); |
||||
} |
||||
if (i > 0 && i <= LOOP_NUM) |
||||
workEnd(); |
||||
|
||||
if (i == LOOP_NUM) |
||||
{ |
||||
if (useCPU) |
||||
cout << "average CPU time (noCamera) : "; |
||||
else |
||||
cout << "average GPU time (noCamera) : "; |
||||
cout << getTime() / LOOP_NUM << " ms" << endl; |
||||
|
||||
getFlowField(flow_vec[0], flow_vec[1], show_flow); |
||||
imshow("PyrLK [Sparse]", show_flow); |
||||
imwrite(outpath, show_flow); |
||||
} |
||||
} |
||||
} |
||||
|
||||
waitKey(); |
||||
|
||||
return 0; |
||||
} |
Loading…
Reference in new issue