-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add WarpPerspective in FastCV extension #3922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
quic-xuezha
wants to merge
2
commits into
opencv:4.x
Choose a base branch
from
CodeLinaro:xuezha_4thPost
base: 4.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,25 @@ | ||
/* | ||
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* Copyright (c) 2024-2025 Qualcomm Innovation Center, Inc. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "perf_precomp.hpp" | ||
|
||
namespace opencv_test { | ||
|
||
typedef perf::TestBaseWithParam<Size> WarpPerspective2PlanePerfTest; | ||
|
||
PERF_TEST_P(WarpPerspective2PlanePerfTest, run, | ||
::testing::Values(perf::szVGA, perf::sz720p, perf::sz1080p)) | ||
static void getInvertMatrix(Mat& src, Mat& dst, Mat& M) | ||
{ | ||
cv::Size dstSize = GetParam(); | ||
cv::Mat img = imread(cvtest::findDataFile("cv/shared/baboon.png")); | ||
Mat src(img.rows, img.cols, CV_8UC1); | ||
cvtColor(img,src,cv::COLOR_BGR2GRAY); | ||
cv::Mat dst1, dst2, mat; | ||
mat.create(3,3,CV_32FC1); | ||
dst1.create(dstSize,CV_8UC1); | ||
dst2.create(dstSize,CV_8UC1); | ||
|
||
RNG& rng = cv::theRNG(); | ||
Point2f s[4], d[4]; | ||
|
||
s[0] = Point2f(0,0); | ||
d[0] = Point2f(0,0); | ||
s[1] = Point2f(src.cols-1.f,0); | ||
d[1] = Point2f(dst1.cols-1.f,0); | ||
d[1] = Point2f(dst.cols-1.f,0); | ||
s[2] = Point2f(src.cols-1.f,src.rows-1.f); | ||
d[2] = Point2f(dst1.cols-1.f,dst1.rows-1.f); | ||
d[2] = Point2f(dst.cols-1.f,dst.rows-1.f); | ||
s[3] = Point2f(0,src.rows-1.f); | ||
d[3] = Point2f(0,dst1.rows-1.f); | ||
d[3] = Point2f(0,dst.rows-1.f); | ||
|
||
float buffer[16]; | ||
Mat tmp( 1, 16, CV_32FC1, buffer ); | ||
|
@@ -41,18 +29,65 @@ PERF_TEST_P(WarpPerspective2PlanePerfTest, run, | |
{ | ||
s[i].x += buffer[i*4]*src.cols/2; | ||
s[i].y += buffer[i*4+1]*src.rows/2; | ||
d[i].x += buffer[i*4+2]*dst1.cols/2; | ||
d[i].y += buffer[i*4+3]*dst1.rows/2; | ||
d[i].x += buffer[i*4+2]*dst.cols/2; | ||
d[i].y += buffer[i*4+3]*dst.rows/2; | ||
} | ||
|
||
cv::getPerspectiveTransform( s, d ).convertTo( mat, mat.depth() ); | ||
cv::getPerspectiveTransform( s, d ).convertTo( M, M.depth() ); | ||
|
||
// Invert the perspective matrix | ||
invert(mat,mat); | ||
invert(M,M); | ||
} | ||
|
||
typedef perf::TestBaseWithParam<Size> WarpPerspective2PlanePerfTest; | ||
|
||
PERF_TEST_P(WarpPerspective2PlanePerfTest, run, | ||
::testing::Values(perf::szVGA, perf::sz720p, perf::sz1080p)) | ||
{ | ||
cv::Size dstSize = GetParam(); | ||
cv::Mat img = imread(cvtest::findDataFile("cv/shared/baboon.png")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add |
||
Mat src(img.rows, img.cols, CV_8UC1); | ||
cvtColor(img,src,cv::COLOR_BGR2GRAY); | ||
cv::Mat dst1, dst2, matrix; | ||
matrix.create(3,3,CV_32FC1); | ||
dst1.create(dstSize,CV_8UC1); | ||
dst2.create(dstSize,CV_8UC1); | ||
|
||
getInvertMatrix(src, dst1, matrix); | ||
|
||
while (next()) | ||
{ | ||
startTimer(); | ||
cv::fastcv::warpPerspective2Plane(src, src, dst1, dst2, matrix, dstSize); | ||
stopTimer(); | ||
} | ||
|
||
SANITY_CHECK_NOTHING(); | ||
} | ||
|
||
typedef perf::TestBaseWithParam<tuple<Size, int, int>> WarpPerspectivePerfTest; | ||
|
||
PERF_TEST_P(WarpPerspectivePerfTest, run, | ||
::testing::Combine( ::testing::Values(perf::szVGA, perf::sz720p, perf::sz1080p), | ||
::testing::Values(INTER_NEAREST, INTER_LINEAR, INTER_AREA), | ||
::testing::Values(BORDER_CONSTANT, BORDER_REPLICATE, BORDER_TRANSPARENT))) | ||
{ | ||
cv::Size dstSize = get<0>(GetParam()); | ||
int interplation = get<1>(GetParam()); | ||
int borderType = get<2>(GetParam()); | ||
cv::Scalar borderValue = Scalar::all(100); | ||
|
||
cv::Mat src = imread(cvtest::findDataFile("cv/shared/baboon.png"), cv::IMREAD_GRAYSCALE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same assert. |
||
cv::Mat dst, matrix, ref; | ||
matrix.create(3, 3, CV_32FC1); | ||
dst.create(dstSize, src.type()); | ||
|
||
getInvertMatrix(src, dst, matrix); | ||
|
||
while (next()) | ||
{ | ||
startTimer(); | ||
cv::fastcv::warpPerspective2Plane(src, src, dst1, dst2, mat, dstSize); | ||
cv::fastcv::warpPerspective(src, dst, matrix, dstSize, interplation, borderType, borderValue); | ||
stopTimer(); | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the information about sizes. The destination buffer is allocated by the function itself automatically.