Ask Your Question

678098's profile - activity

2017-06-19 09:33:10 -0600 commented answer img = img1*mask + img2*(1-mask) How do that ?

Can thread creation be a problem? Are you making 4 new threads for each image? https://stackoverflow.com/questions/3929774/how-much-overhead-is-there-when-creating-a-thread

2017-06-19 08:57:03 -0600 commented answer img = img1*mask + img2*(1-mask) How do that ?

How are you measuring time? Have you considered granularity of time measurement? When completion time is small, It is right to use loops for precision:

int64 startingTick = cv::getTickCount();
const int repeatsNum = 1000;
for (int i = 0; i < repeatsNum; i++){
    yourMethodToMeasure();
}
double timeDiff = (cv::getTickCount() - startingTick)/cv::getTickFrequency()/repeatsNum;
2017-06-19 05:59:56 -0600 commented question img = img1*mask + img2*(1-mask) How do that ?

Why your code is slow? There are 2 reasons: 1)You are using .at, which is slower than pointer access. 2)You are using Vec3b for pixel access. Every time you are writing .at<vec3b>, new object of class Vec3b is being created.

template<typename _Tp, int n> class Vec : public Matx<_Tp, n, 1> {...};
typedef Vec<uchar, 3> Vec3b
2017-06-19 05:51:05 -0600 commented question img = img1*mask + img2*(1-mask) How do that ?

You can modify your loop body to make it faster:

const uchar *scale = &greyGoodScale.at<uchar>(j, 0);
uchar *imgdata = &img.at<uchar>(j, 0);
const uchar *imgdata1 = &img1.at<uchar>(j, 0);
const uchar *imgdata2 = &img2.at<uchar>(j, 0);
for(int i = 0; i < img1.cols ; i++ ){
    c1 = scale[i]/255.0;
    c2 = 1-c1;
    int pos = 3*i;
    for (int k = 0; k < 3; k++){
        imgdata[pos + k] = c2*imgdata1[pos + k] + c1*imgdata2[pos + k];
    }
}

To make It even faster you can make conversion table from uchar to double for c1. Just preprocess values from 0/255.0 to 255.0/255.0. And you can preprocess 1 - c1 too.

2017-06-19 05:48:54 -0600 commented question How to load old format cascade on OpenCV 2.4.10?

I used my custom cascade, which has been trained about 2 years ago. I don't even remember where the training data is.

By the way, I successfully launched ocl cascade with old-format cascades from opencv distribution.

And I found in cv version 3 sources cascades converter from old to new: https://github.com/opencv/opencv/blob/master/modules/objdetect/src/cascadedetect_convert.cpp

So the questions is: is converter from new to old format needed?

2017-06-16 08:11:45 -0600 asked a question How to load old format cascade on OpenCV 2.4.10?

I am currently trying to use cv::ocl::OclCascadeClassifier, but It uses oldCascade only which is NULL (so I got invalid cascade cv exception).

Method isOldFormatCascade() returns false, method load() returns true.

If I use cv::CascadeClassifier, all works fine (because there are 2 branches in its implementation: for old format and for new format cascades).

cv::Mat image = cv::Mat::zeros(cv::Size(2000, 700), CV_8UC1);
cv::ocl::oclMat image_igpu;
image_igpu.upload(image);
cv::Size min_size(50, 10);
cv::Size max_size(100, 20);

cv::CascadeClassifier cascade_cpu;
cv::ocl::OclCascadeClassifier cascade_igpu;
cascade_cpu.load("cascade.xml");
cascade_igpu.load("cascade.xml");

std::cout << cascade_igpu.isOldFormatCascade() << std::endl;//prints 0 (false), same as cascade_cpu.isOldFormatCascade()


std::vector<cv::Rect> objs;
cascade_cpu.detectMultiScale(image, objs, 1.1, 0, 0, min_size, max_size);//works fine
cascade_igpu.detectMultiScale(image_igpu, objs, 1.1, 0, 0, min_size, max_size);//OpenCV Error: Null pointer (Invalid classifier cascade) in oclHaarDetectObjects