mirror of
https://github.com/zhigang1992/PerspectiveTransform.git
synced 2026-04-28 20:25:12 +08:00
* use whole module compilation mode to workaround intermittent code sign failures, see https://travis-ci.org/paulz/PerspectiveTransform/jobs/481952493#L985 that could be caused by known Xcode 10 issue: https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes/build_system_release_notes_for_xcode_10 * reuse test images from the app in app specs * exclude svg from app specs as it is not used * exclude metadata files from Example app build * Revert "reuse test images from the app in app specs" This reverts commit 9b18b81a036adc547771efed10cfe13e56f9c207. * disallow warnings in pod lib lint, make SnapshotSpec work with or without app resources * disable localization * remove unused xcconfig files * enable batch mode experiment to workaround code sign issues: https://github.com/Yummypets/YPImagePicker/issues/236 * delete all code signing build settings * fix framework specs dependency on the example app * move scheme to workspace, disable auto create, ignore playground compiled files * reuse test bundle info, remove unused build settings * reset bundle indentifiers to the same value * remove module name * clean mac target build settings * remove unused FRAMEWORK_SEARCH_PATHS * reuse wrapper header as bridging * reuse before install, cache bundler
85 lines
2.6 KiB
Plaintext
85 lines
2.6 KiB
Plaintext
#pragma GCC diagnostic push
|
|
#pragma GCC diagnostic ignored "-Wdocumentation"
|
|
/**
|
|
OpenCV library is dynamically linked, to install OpenCV:
|
|
|
|
brew install opencv
|
|
*/
|
|
#import <opencv2/opencv.hpp>
|
|
#pragma GCC diagnostic pop
|
|
#import "OpenCVWrapper.h"
|
|
|
|
@implementation OpenCVWrapper
|
|
+ (CATransform3D)findHomographyFromQuadrilateral:(Quadrilateral)origin toQuadrilateral:(Quadrilateral)destination {
|
|
CvPoint2D32f *cvsrc = [self openCVMatrixWithQuadrilateral:origin];
|
|
CvMat *src_mat = cvCreateMat( 4, 2, CV_32FC1 );
|
|
cvSetData(src_mat, cvsrc, sizeof(CvPoint2D32f));
|
|
|
|
CvPoint2D32f *cvdst = [self openCVMatrixWithQuadrilateral:destination];
|
|
CvMat *dst_mat = cvCreateMat( 4, 2, CV_32FC1 );
|
|
cvSetData(dst_mat, cvdst, sizeof(CvPoint2D32f));
|
|
|
|
CvMat *H = cvCreateMat(3,3,CV_32FC1);
|
|
cvFindHomography(src_mat, dst_mat, H);
|
|
cvReleaseMat(&src_mat);
|
|
cvReleaseMat(&dst_mat);
|
|
|
|
CATransform3D transform = [self transform3DWithCMatrix:H->data.fl];
|
|
cvReleaseMat(&H);
|
|
|
|
return transform;
|
|
}
|
|
|
|
+ (CATransform3D)perspectiveTransform:(Quadrilateral)origin toQuadrilateral:(Quadrilateral)destination {
|
|
CvPoint2D32f *cvsrc = [self openCVMatrixWithQuadrilateral:origin];
|
|
CvMat *src_mat = cvCreateMat( 4, 2, CV_32FC1 );
|
|
cvSetData(src_mat, cvsrc, sizeof(CvPoint2D32f));
|
|
|
|
CvPoint2D32f *cvdst = [self openCVMatrixWithQuadrilateral:destination];
|
|
CvMat *dst_mat = cvCreateMat( 4, 2, CV_32FC1 );
|
|
cvSetData(dst_mat, cvdst, sizeof(CvPoint2D32f));
|
|
|
|
CvMat *H = cvCreateMat(3,3,CV_32FC1);
|
|
cvGetPerspectiveTransform(cvsrc, cvdst, H);
|
|
cvReleaseMat(&src_mat);
|
|
cvReleaseMat(&dst_mat);
|
|
|
|
CATransform3D transform = [self transform3DWithCMatrix:H->data.fl];
|
|
cvReleaseMat(&H);
|
|
|
|
return transform;
|
|
}
|
|
|
|
+ (CvPoint2D32f *)openCVMatrixWithQuadrilateral:(Quadrilateral)origin {
|
|
|
|
CvPoint2D32f *cvsrc = (CvPoint2D32f *)malloc(4*sizeof(CvPoint2D32f));
|
|
cvsrc[0].x = origin.upperLeft.x;
|
|
cvsrc[0].y = origin.upperLeft.y;
|
|
cvsrc[1].x = origin.upperRight.x;
|
|
cvsrc[1].y = origin.upperRight.y;
|
|
cvsrc[2].x = origin.lowerRight.x;
|
|
cvsrc[2].y = origin.lowerRight.y;
|
|
cvsrc[3].x = origin.lowerLeft.x;
|
|
cvsrc[3].y = origin.lowerLeft.y;
|
|
return cvsrc;
|
|
}
|
|
|
|
+ (CATransform3D)transform3DWithCMatrix:(float *)matrix {
|
|
CATransform3D transform = CATransform3DIdentity;
|
|
|
|
transform.m11 = matrix[0];
|
|
transform.m21 = matrix[1];
|
|
transform.m41 = matrix[2];
|
|
|
|
transform.m12 = matrix[3];
|
|
transform.m22 = matrix[4];
|
|
transform.m42 = matrix[5];
|
|
|
|
transform.m14 = matrix[6];
|
|
transform.m24 = matrix[7];
|
|
transform.m44 = matrix[8];
|
|
|
|
return transform;
|
|
}
|
|
@end
|