【问题标题】:OpenCV, Android: Draw Line on bitmapOpenCV,Android:在位图上画线
【发布时间】:2017-08-14 06:15:21
【问题描述】:

我目前有一个应用程序,onClick 将在电池和蓝色纸条周围绘制一个绿色边界矩形。我还想让按钮onClick 从电池到纸条画一条线(如下图第二张所示)。目前我能够获得矩形的所有 x 和 y 值,因此知道我需要从534,1261788,1261 画一条线,并用 x 差异标记线,如图所示。

【问题讨论】:

    标签: java android opencv bitmap


    【解决方案1】:

    对于画线和文字你可以使用这样的代码:

    Point firstPoint = new Point(100, 200);
    Point secondPoint = new Point(100, 400);
    Point middlePoint = new Point(firstPoint.x,
            firstPoint.y + 0.5 * (secondPoint.y -  firstPoint.y));
    
    Scalar lineColor = new Scalar(255, 0, 0, 255);
    int lineWidth = 3;
    
    Scalar textColor = new Scalar(255, 0, 0, 255);
    
    Imgproc.line(sourceMat, firstPoint, secondPoint, lineColor, lineWidth);
    Imgproc.putText(sourceMat, " Text" , middlePoint,
            Core.FONT_HERSHEY_PLAIN, 1.5 , textColor);
    

    sourceMat - Mat 带有图片。

    为了确定以厘米为单位的行“高度”(大约),您应该使用电池矩形的“高度”:

    lineHeightCm = 4.46 / heightOfBatteryRectangleInPixels * lineHeightInPixels;
    

    其中 4.46 - AAA 电池的“高度”,以厘米为单位。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-09
      • 1970-01-01
      相关资源
      最近更新 更多