对android和c ++的回应有不同的影响

时间:2015-07-19 14:35:56

标签: android opencv

这是我的c ++,opencv代码,它基本上覆盖了cameraFeed上指定位置的图像。

Mat transmix = getPerspectiveTransform(imagePoints, newLEDPoints);
            warpPerspective(repImage, cameraFeed, transmix, cameraFeed.size(), cv::INTER_LINEAR,   cv::BORDER_TRANSPARENT);

这里imagePoints和newLEDPoints是两个向量,包含正确顺序的四个笛卡尔点。我试图在android中实现类似的效果,opencv这里是代码

以drawable

阅读图片
try {
        repImage = Utils.loadResource(this, R.drawable.ring, Highgui.CV_LOAD_IMAGE_COLOR);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

现在为每个框架

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    // TODO Auto-generated method stub
    Log.i(TAG, "called onCameraFrame");
    cameraFeed = inputFrame.rgba();
    Point center = new Point(cameraFeed.width()/2, cameraFeed.height()/2);
    Point topLeft = new Point( center.x - 100, center.y - 100 );
    Point topRight = new Point( center.x + 100, center.y - 100);
    Point bottomRight = new Point( center.x + 100, center.y + 100 );
    Point bottomLeft = new  Point( center.x - 100, center.y + 100 );
    List<Point> LEDPoints = new ArrayList<Point>();
    LEDPoints.add( topLeft );
    LEDPoints.add( topRight );
    LEDPoints.add( bottomRight );
    LEDPoints.add( bottomLeft );
    Log.i(TAG, "Before LEDPoint Conversion");
    Mat LEDPointss = Converters.vector_Point2f_to_Mat( LEDPoints );

    List<Point> imagePoints = new ArrayList<Point>();
    imagePoints.add( new Point( 0, 0));
    imagePoints.add( new Point( repImage.width(), 0 ));
    imagePoints.add( new Point( repImage.width(), repImage.height()));
    imagePoints.add( new Point( 0, repImage.height()));
    Log.i(TAG, "Before imagePoint Conversion");
    Mat imagePointss = Converters.vector_Point2f_to_Mat( imagePoints );

    Log.i(TAG, "Before transmix");
    Mat transmix = Imgproc.getPerspectiveTransform(imagePointss, LEDPointss);

    Log.i(TAG, "Before warp");


    if ( !repImage.empty())
    {
        Imgproc.warpPerspective(repImage, 
            cameraFeed,
            transmix,
            cameraFeed.size(), 
            Imgproc.INTER_LINEAR);
    }
    else
    {
        Log.i(TAG, "repImage is empty");
    }
    Scalar color = new Scalar( 0, 255, 0 );
    Core.circle(cameraFeed, center, 10, color, 2);

    return cameraFeed;
}

当我在Android平板电脑上运行时,我只是在屏幕上获取repImage。我实际上希望repImage出现在cameraFeed上规定的坐标(正如我的c ++代码那样)请指导我,我错过了什么?或者我做错了什么?

0 个答案:

没有答案