Hi all, I use mat format to calculate an matrix, also i use traditions C++ calculate an matix. But I find out, mat format is very slowly.Could someone tell me reason and how to improve the efficiency. Any help is highly appreciated! Thanks:) Here is my code:
traditions method where sw=src2.step,it almost costs 5 number of ticks/one cycle.
for (int k=0;k<100;k++) { int A = getTickCount();
for (int iwr = 0; iwr <= 11; iwr++ ) { /* Sub-Window 0 / for (int iwc =0; iwc <= 11; iwc++ ) { gray_val =src2.data[iwrsw+iwc]; sum[0] += gray_val; sum_sq[0] += gray_val * gray_val; }/* Sub-Window 1 */ for (int iwc = 0; iwc <=11; iwc++ ) { gray_val = src2.data[iwr*sw+iwc]; sum[1] += gray_val; sum_sq[1] += gray_val * gray_val; } } int B = getTickCount(); int c=B-A;
}
2.it almost costs 138 number of ticks/one cycle.
for(int k=0;k<100;k++)
{
int A = getTickCount();
Mat ROIimage1(src2, Rect(ic-half_win,ir- half_win,r,r) );
sum1=cv::sum(ROIimage1);
cv::multiply(ROIimage1,ROIimage1,square1);
sum_sq1=cv::sum(square1);
int B = getTickCount();
int c=B-A;
}