【问题标题】:Android Studio - Error cannot find symbol class R while compiling OpenCVAndroid Studio - 编译 OpenCV 时出错找不到符号类 R
【发布时间】:2015-09-30 18:11:21
【问题描述】:

我正在尝试使用 Opencv 编译一个项目,但我一直遇到这个问题:错误:(5, 18) 错误:找不到符号类 R

错误发生在:import org.opencv.R;

这只是我收到错误的代码的一部分:

package br.raphael.extended;
import java.util.List;
import org.opencv.R;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.highgui.Highgui;

import br.raphael.detector.FpsMeterExtended;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

/**
 * This is a basic class, implementing the interaction with Camera and OpenCV library.
 * The main responsibility of it - is to control when camera can be enabled, process the frame,
 * call external listener to make any adjustments to the frame and then draw the resulting
 * frame to the screen.
 * The clients shall implement CvCameraViewListener.
 */
public abstract class CameraBridgeViewBaseExtended extends SurfaceView implements SurfaceHolder.Callback {

    private static final String TAG = "CameraBridge";
    private static final int MAX_UNSPECIFIED = -1;
    private static final int STOPPED = 0;
    private static final int STARTED = 1;

    private int mState = STOPPED;
    private Bitmap mCacheBitmap;
    private CvCameraViewListener2 mListener;
    private boolean mSurfaceExist;
    private Object mSyncObject = new Object();

    protected int mFrameWidth;
    protected int mFrameHeight;
    protected int mMaxHeight;
    protected int mMaxWidth;
    protected int mPreviewFormat = Highgui.CV_CAP_ANDROID_COLOR_FRAME_RGBA;
    protected int mCameraIndex = -1;
    protected boolean mEnabled;
    protected FpsMeterExtended mFpsMeter = null;

    public CameraBridgeViewBaseExtended(Context context, int cameraId) {
        super(context);
        mCameraIndex = cameraId;
    }

    public CameraBridgeViewBaseExtended(Context context, AttributeSet attrs) {
        super(context, attrs);

        int count = attrs.getAttributeCount();
        Log.d(TAG, "Attr count: " + Integer.valueOf(count));

        TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase);
        if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
            enableFpsMeter();

        mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, -1);

        getHolder().addCallback(this);
        mMaxWidth = MAX_UNSPECIFIED;
        mMaxHeight = MAX_UNSPECIFIED;
    }

【问题讨论】:

    标签: java android opencv android-studio compilation


    【解决方案1】:

    如果您在提及 import org.opencv.R 时遇到错误,则表示您的某些 xml 视图页面中存在错误。重新检查您的 XML 页面


    【讨论】:

    • 我认为问题可能出在这里:TypedArray styledAttrs = getContext().obtainStyledAttributes(attrs, R.styleable.CameraBridgeViewBase); 在 OpenCV res 文件夹中,我有这个 attrs 文件,其中包含:<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name = "CameraBridgeViewBase" > <attr name="show_fps" format="boolean"/> <attr name="camera_id" format="integer" > <enum name="any" value="-1" /> <enum name="back" value="99" /> <enum name="front" value="98" /> </attr> </declare-styleable> </resources>
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 1970-01-01
    • 2016-03-02
    相关资源
    最近更新 更多