本文整理汇总了Java中org.opencv.imgproc.Imgproc.warpAffine方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.warpAffine方法的具体用法?Java Imgproc.warpAffine怎么用?Java Imgproc.warpAffine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.imgproc.Imgproc
的用法示例。
在下文中一共展示了Imgproc.warpAffine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rotate
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
* Rotate an image by an angle (counterclockwise)
*
* @param image Transform matrix
* @param angle Angle to rotate by (counterclockwise) from -360 to 360
*/
public static void rotate(Mat image, double angle) {
//Calculate size of new matrix
double radians = Math.toRadians(angle);
double sin = Math.abs(Math.sin(radians));
double cos = Math.abs(Math.cos(radians));
int newWidth = (int) (image.width() * cos + image.height() * sin);
int newHeight = (int) (image.width() * sin + image.height() * cos);
// rotating image
Point center = new Point(newWidth / 2, newHeight / 2);
Mat rotMatrix = Imgproc.getRotationMatrix2D(center, angle, 1.0); //1.0 means 100 % scale
Size size = new Size(newWidth, newHeight);
Imgproc.warpAffine(image, image, rotMatrix, image.size());
}
示例2: onCameraFrame
import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
mNativeDetector.setMinFaceSize(mAbsoluteFaceSize);
}
MatOfRect faces = new MatOfRect();
if (mDetectorType == JAVA_DETECTOR) {
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize), new Size());
} else if (mDetectorType == NATIVE_DETECTOR) {
if (mNativeDetector != null)
mNativeDetector.detect(mGray, faces);
} else {
Log.e(TAG, "Detection method is not selected!");
}
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++) {
Imgproc.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), FACE_RECT_COLOR, 3);
}
//转置90度
Mat rotateMat = Imgproc.getRotationMatrix2D(new Point(mRgba.rows() / 2, mRgba.cols() / 2), 90, 1);
Imgproc.warpAffine(mRgba, mRgba, rotateMat, mRgba.size());
//以y轴翻转
Core.flip(mRgba, mRgba, 1);
return mRgba;
}