gpt4 book ai didi

android - 如何在 OpenCV Camera Preview 上画线?

转载 作者:太空宇宙 更新时间:2023-11-03 22:32:05 25 4
gpt4 key购买 nike

我正在使用 OpenCV 相机预览。

我想在实时预览上绘制一个矩形。我试图重写 ondraw 方法,但我看不到一行。请帮忙。

package com.example.easymeasure;

import org.opencv.android.JavaCameraView;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;

public class CustomOpenCVJavaCameraView extends JavaCameraView {

public CustomOpenCVJavaCameraView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

private Paint linePaint;
protected void init() {
Resources r = this.getResources();
linePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
linePaint.setAlpha(200);
linePaint.setStrokeWidth(1);
linePaint.setStyle(Paint.Style.STROKE);
linePaint.setColor(r.getColor(R.color.marker_color));
linePaint.setShadowLayer(2, 1, 1, r.getColor(R.color.shadow_color));
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
linePaint.setStrokeWidth(5);
canvas.drawLine(10,20,1000,200,linePaint);
}
}

最佳答案

这是解决方案:Extended SurfaceView's onDraw() method never called

您只需添加:

setWillNotDraw(false)

致构造函数

关于android - 如何在 OpenCV Camera Preview 上画线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21530947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com