嗨我想改变图像的视角并将其与antoher图像合并。我发现在c ++中使用opencv库编写的示例,我试图将其转换为android,但我发现错误没有找到长org.opencv.highgui的实现。 这是我的代码:
public class TransformationImage {
private MatOfPoint2f pointsOfSuperimposedImage;
private MatOfPoint2f pointsOfMainImage;
private Mat imageMain;
private Mat imagelogo;
public TransformationImage(String imageMainPath, String imageLogoPath) {
this.imagelogo = Highgui.imread(imageLogoPath);
this.imageMain = Highgui.imread(imageMainPath);
pointsOfMainImage = new MatOfPoint2f();
pointsOfSuperimposedImage = new MatOfPoint2f();
}
public Bitmap transformTwoImages(){
Mat finalTransformedImage;
Bitmap bitmap = Bitmap.createBitmap(552, 256, Bitmap.Config.ARGB_4444);
setMainImageVectors();
setAppliedImagePosition();
setWarpPerspectiveOfTwoImages();
finalTransformedImage = showFinal(pointsOfMainImage, pointsOfMainImage);
Utils.matToBitmap(finalTransformedImage, bitmap);
return bitmap;
}
private Mat showFinal(Mat firstImage, Mat secondImage){
Mat gray = new Mat();
Mat gray_inv = new Mat();
Mat src1final = new Mat();
Mat src2final = new Mat();
cvtColor(secondImage, gray, Imgproc.COLOR_BGR2GRAY);
threshold(gray, gray, 0, 255, 0);
bitwise_not(gray, gray_inv);
firstImage.copyTo(src2final, gray_inv);
secondImage.copyTo(src1final, gray);
addWeighted(src1final, 0, src2final, 0, 0, src1final);
return src1final;
}
private void setWarpPerspectiveOfTwoImages(){
Imgproc.warpPerspective(imagelogo, imageMain, Calib3d.findHomography(pointsOfSuperimposedImage, pointsOfMainImage), imageMain.size());
}
private void setMainImageVectors(){
List<Point> src_pnt = new ArrayList<>();
Point p0 = new Point(0, 0);
src_pnt.add(p0);
Point p1 = new Point(552, 0);
src_pnt.add(p1);
Point p2 = new Point(0, 256);
src_pnt.add(p2);
Point p3 = new Point(552, 256);
src_pnt.add(p3);
pointsOfMainImage.push_back(Converters.vector_Point2f_to_Mat(src_pnt));
}
private void setAppliedImagePosition(){
List<Point> src_pnt = new ArrayList<>();
Point p0 = new Point(0, 0);
src_pnt.add(p0);
Point p1 = new Point(50, 0);
src_pnt.add(p1);
Point p2 = new Point(50, 20);
src_pnt.add(p2);
Point p3 = new Point(20, 0);
src_pnt.add(p3);
pointsOfSuperimposedImage.push_back(Converters.vector_Point2f_to_Mat(src_pnt));
}
}
以下是c ++ http://ramsrigoutham.com/2014/06/14/perspective-projection-with-homography-opencv/#comment-8114
中的代码示例我通过导入模块将opencv库导入android studio中的项目。