Skip to content

Add warpAffine IPPIW implementation to replace with old version#22074

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
bwang30:opencv-warpAffine-ippiw
Oct 4, 2022
Merged

Add warpAffine IPPIW implementation to replace with old version#22074
asmorkalov merged 1 commit intoopencv:4.xfrom
bwang30:opencv-warpAffine-ippiw

Conversation

@bwang30
Copy link
Copy Markdown
Contributor

@bwang30 bwang30 commented Jun 7, 2022

The old version of IPP warpaffine can't work(can't pass build) which was controlled by flag IPP_DISABLE_WARPAFFINE.
This pull request provides IPPIW warpaffine version controlled by flag HAVE_IPP_IW , and check ipp NE flag for the different result issue between OpenCV and IPP.

Tested 100 images with src size is 1920x1080, data type is CV_8UC3, ROI is the whole image:

image

code snippet as following:

const int bordertype = cv::BORDER_CONSTANT;
int interpolation = cv::INTER_LINEAR; 
double angle = 30;                    

vector<cv::Mat> srcData;
for (auto imgpath : sInputFiles)
{
    Mat img = cv::imread(imgpath, cv::IMREAD_COLOR);
    cv::Size dsize(1920, 1080);
    Mat img_resized;
    cv::resize(img, img_resized, dsize, 0, 0, cv::INTER_CUBIC);
    srcData.push_back(img);
  }

vector<cv::Mat> dstData(srcData.size());
...
cv::Mat M = cv::getRotationMatrix2D(center, rotateAngle, scale);

double radianAngle = rotateAngle * 3.14159 / 180;
int drows = int(cols * fabs(sin(radianAngle)) + rows * fabs(cos(radianAngle)));
int dcols = int(rows * fabs(sin(radianAngle)) + cols * fabs(cos(radianAngle)));
M.at<double>(0, 2) += (dcols - cols) / 2;
M.at<double>(1, 2) += (drows - rows) / 2;

cv::warpAffine(src, dst, M, Size(dcols, drows), interpolation, bordertype, Scalar(0, 0, 0));

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@bwang30 bwang30 changed the title Add warpAffine IPPIW implementation protected by ipp NE flag Add warpAffine IPPIW implementation to replace with old version Jun 7, 2022
@asmorkalov asmorkalov requested a review from vpisarev October 3, 2022 13:00
@vpisarev
Copy link
Copy Markdown
Contributor

vpisarev commented Oct 3, 2022

@bwang30, thank you! 👍

Signed-off-by: robin <bin.wang@intel.com>
@asmorkalov
Copy link
Copy Markdown
Contributor

Rebased to 4.x and squashed commits.

@asmorkalov asmorkalov force-pushed the opencv-warpAffine-ippiw branch from ba5dd0f to ed3b56d Compare October 4, 2022 05:42
@asmorkalov asmorkalov added this to the 4.7.0 milestone Oct 4, 2022
@asmorkalov
Copy link
Copy Markdown
Contributor

asmorkalov commented Oct 4, 2022

OpenCV performance test status:

Geometric mean (ms)

                              Name of Test                               warpaffine warpaffine warpaffine
                                                                          default      ipp        ipp    
                                                                                                   vs    
                                                                                               warpaffine
                                                                                                default  
                                                                                               (x-factor)
WarpAffine::TestWarpAffine::(640x480, INTER_LINEAR, BORDER_CONSTANT)       0.573      0.518       1.11   
WarpAffine::TestWarpAffine::(640x480, INTER_LINEAR, BORDER_REPLICATE)      0.560      0.429       1.31   
WarpAffine::TestWarpAffine::(640x480, INTER_NEAREST, BORDER_CONSTANT)      0.411      0.303       1.36   
WarpAffine::TestWarpAffine::(640x480, INTER_NEAREST, BORDER_REPLICATE)     0.247      0.307       0.80   
WarpAffine::TestWarpAffine::(1280x720, INTER_LINEAR, BORDER_CONSTANT)      0.582      0.579       1.01   
WarpAffine::TestWarpAffine::(1280x720, INTER_LINEAR, BORDER_REPLICATE)     1.128      1.117       1.01   
WarpAffine::TestWarpAffine::(1280x720, INTER_NEAREST, BORDER_CONSTANT)     0.515      0.411       1.25   
WarpAffine::TestWarpAffine::(1280x720, INTER_NEAREST, BORDER_REPLICATE)    0.465      0.496       0.94   
WarpAffine::TestWarpAffine::(1920x1080, INTER_LINEAR, BORDER_CONSTANT)     1.263      1.141       1.11   
WarpAffine::TestWarpAffine::(1920x1080, INTER_LINEAR, BORDER_REPLICATE)    3.937      3.717       1.06   
WarpAffine::TestWarpAffine::(1920x1080, INTER_NEAREST, BORDER_CONSTANT)    0.888      0.861       1.03   
WarpAffine::TestWarpAffine::(1920x1080, INTER_NEAREST, BORDER_REPLICATE)   1.016      1.001       1.02   

System: AMD Ryzen 7 2700X (8 cores), 64GB RAM.

@alalek
Copy link
Copy Markdown
Member

alalek commented Oct 4, 2022

Results above show performance measurement instability.
Optimization code is guarded by useIPP_NotExact() flag.
Extra steps are required, like OPENCV_IPP=NE env should be used.

@asmorkalov
Copy link
Copy Markdown
Contributor

Yes, I've already found it.

@asmorkalov
Copy link
Copy Markdown
Contributor

New statistics with IPP NE forced to true:

WarpAffine::TestWarpAffine::(640x480, INTER_LINEAR, BORDER_CONSTANT)       0.573      0.256       2.24   
WarpAffine::TestWarpAffine::(640x480, INTER_LINEAR, BORDER_REPLICATE)      0.560      0.226       2.48   
WarpAffine::TestWarpAffine::(640x480, INTER_NEAREST, BORDER_CONSTANT)      0.411      0.114       3.62   
WarpAffine::TestWarpAffine::(640x480, INTER_NEAREST, BORDER_REPLICATE)     0.247      0.058       4.23   
WarpAffine::TestWarpAffine::(1280x720, INTER_LINEAR, BORDER_CONSTANT)      0.582      failed       -     
WarpAffine::TestWarpAffine::(1280x720, INTER_LINEAR, BORDER_REPLICATE)     1.128      0.771       1.46   
WarpAffine::TestWarpAffine::(1280x720, INTER_NEAREST, BORDER_CONSTANT)     0.515      failed       -     
WarpAffine::TestWarpAffine::(1280x720, INTER_NEAREST, BORDER_REPLICATE)    0.465      0.159       2.93   
WarpAffine::TestWarpAffine::(1920x1080, INTER_LINEAR, BORDER_CONSTANT)     1.263      failed       -     
WarpAffine::TestWarpAffine::(1920x1080, INTER_LINEAR, BORDER_REPLICATE)    3.937      1.307       3.01   
WarpAffine::TestWarpAffine::(1920x1080, INTER_NEAREST, BORDER_CONSTANT)    0.888      failed       -     
WarpAffine::TestWarpAffine::(1920x1080, INTER_NEAREST, BORDER_REPLICATE)   1.016      0.311       3.27 

@asmorkalov asmorkalov merged commit 8f0edf6 into opencv:4.x Oct 4, 2022
@xethan666
Copy link
Copy Markdown

New statistics with IPP NE forced to true:

WarpAffine::TestWarpAffine::(640x480, INTER_LINEAR, BORDER_CONSTANT)       0.573      0.256       2.24   
WarpAffine::TestWarpAffine::(640x480, INTER_LINEAR, BORDER_REPLICATE)      0.560      0.226       2.48   
WarpAffine::TestWarpAffine::(640x480, INTER_NEAREST, BORDER_CONSTANT)      0.411      0.114       3.62   
WarpAffine::TestWarpAffine::(640x480, INTER_NEAREST, BORDER_REPLICATE)     0.247      0.058       4.23   
WarpAffine::TestWarpAffine::(1280x720, INTER_LINEAR, BORDER_CONSTANT)      0.582      failed       -     
WarpAffine::TestWarpAffine::(1280x720, INTER_LINEAR, BORDER_REPLICATE)     1.128      0.771       1.46   
WarpAffine::TestWarpAffine::(1280x720, INTER_NEAREST, BORDER_CONSTANT)     0.515      failed       -     
WarpAffine::TestWarpAffine::(1280x720, INTER_NEAREST, BORDER_REPLICATE)    0.465      0.159       2.93   
WarpAffine::TestWarpAffine::(1920x1080, INTER_LINEAR, BORDER_CONSTANT)     1.263      failed       -     
WarpAffine::TestWarpAffine::(1920x1080, INTER_LINEAR, BORDER_REPLICATE)    3.937      1.307       3.01   
WarpAffine::TestWarpAffine::(1920x1080, INTER_NEAREST, BORDER_CONSTANT)    0.888      failed       -     
WarpAffine::TestWarpAffine::(1920x1080, INTER_NEAREST, BORDER_REPLICATE)   1.016      0.311       3.27 

which HW platform this result based on, also AMD Ryzen 7 2700X (8 cores), 64GB RAM?

@asmorkalov
Copy link
Copy Markdown
Contributor

Yes.

@alalek alalek mentioned this pull request Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants