首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“MyApp”已停止并正在强制关闭

“MyApp”已停止并正在强制关闭
EN

Stack Overflow用户
提问于 2017-12-11 10:44:30
回答 1查看 55关注 0票数 0

我正在使用Opencv库在Android studio上开发Android应用程序,当我尝试打开我的应用程序时,它会打开,然后立即关闭并显示崩溃消息。我是个移动开发新手

使用: OpenCV310,Android Studio3.0,

代码语言:javascript
复制
public class ScanLicensePlateActivity extends AppCompatActivity {

protected AnylineOcrScanView scanView;
private LicensePlateResultView licensePlateResultView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Set the flag to keep the screen on (otherwise the screen may go dark during scanning)
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_anyline_ocr);

    String license = getString(R.string.anyline_license_key);
    // Get the view from the layout
    scanView = (AnylineOcrScanView) findViewById(R.id.scan_view);
    // Configure the view (cutout, the camera resolution, etc.) via json
    // (can also be done in xml in the layout)
    scanView.setConfig(new AnylineViewConfig(this, "license_plate_view_config.json"));

    // Copies given traineddata-file to a place where the core can access it.
    // This MUST be called for every traineddata file that is used
    // (before startScanning() is called).
    // The file must be located directly in the assets directory
    // (or in tessdata/ but no other folders are allowed)
    scanView.copyTrainedData("tessdata/GL-Nummernschild-Mtl7_uml.traineddata",
            "8ea050e8f22ba7471df7e18c310430d8");
    scanView.copyTrainedData("tessdata/Arial.traineddata", "9a5555eb6ac51c83cbb76d238028c485");
    scanView.copyTrainedData("tessdata/Alte.traineddata", "f52e3822cdd5423758ba19ed75b0cc32");
    scanView.copyTrainedData("tessdata/deu.traineddata", "2d5190b9b62e28fa6d17b728ca195776");

    // Configure the OCR for license plate scanning via a custom script file
    // This is how you could add custom scripts optimized by Anyline for your use-case
    AnylineOcrConfig anylineOcrConfig = new AnylineOcrConfig();
    anylineOcrConfig.setCustomCmdFile("license_plates.ale");

    // set the ocr config
    scanView.setAnylineOcrConfig(anylineOcrConfig);

    // initialize with the license and a listener
    scanView.initAnyline(license, new AnylineOcrListener() {
        @Override
        public void onReport(String identifier, Object value) {
            // Called with interesting values, that arise during processing.
            // Some possibly reported values:
            //
            // $brightness - the brightness of the center region of the cutout as a float value
            // $confidence - the confidence, an Integer value between 0 and 100
            // $thresholdedImage - the current image transformed into black and white
            // $sharpness - the detected sharpness value (only reported if minSharpness > 0)
        }

        @Override
        public boolean onTextOutlineDetected(List<PointF> list) {
            // Called when the outline of a possible text is detected.
            // If false is returned, the outline is drawn automatically.
            return false;
        }

        @Override
        public void onResult(AnylineOcrResult result) {
            // Called when a valid result is found
            String results[] = result.getText().split("-");
            String licensePlate = results[1];

            licensePlateResultView.setLicensePlate(licensePlate);
            licensePlateResultView.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAbortRun(AnylineOcrError code, String message) {
            // Is called when no result was found for the current image.
            // E.g. if no text was found or the result is not valid.
        }
    });


    // disable the reporting if set to off in preferences
    if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean(
            SettingsFragment.KEY_PREF_REPORTING_ON, true)) {
        // The reporting of results - including the photo of a scanned meter -
        // helps us in improving our product, and the customer experience.
        // However, if you wish to turn off this reporting feature, you can do it like this:
        scanView.setReportingEnabled(false);
    }
    addLicensePlateResultView();
}

private void addLicensePlateResultView() {
    RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
    params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

    licensePlateResultView = new LicensePlateResultView(this);
    licensePlateResultView.setVisibility(View.INVISIBLE);

    mainLayout.addView(licensePlateResultView, params);
    licensePlateResultView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startScanning();

        }
    });
}

private void startScanning() {
    licensePlateResultView.setVisibility(View.INVISIBLE);
    // this must be called in onResume, or after a result to start the scanning again
    scanView.startScanning();
}

@Override
protected void onResume() {
    super.onResume();
    startScanning();
}

@Override
protected void onPause() {
    super.onPause();

    scanView.cancelScanning();
    scanView.releaseCameraInBackground();
}

@Override
public void onBackPressed() {
    if (licensePlateResultView.getVisibility() == View.VISIBLE) {
        startScanning();
    } else {
        super.onBackPressed();
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
}}

源代码在这里。如果可能的话请帮忙。

Logcat error shown here

EN

回答 1

Stack Overflow用户

发布于 2017-12-11 11:00:13

理想情况下,关于错误的更多信息将是最好的,即opencv库版本等。鉴于这似乎是一个Android问题,我建议

  1. 文件,并在其github页面上发布或查看与此错误相关的issues。搜索相关的安卓错误,看看它们是否匹配。
  2. 如果你找不到相关的错误,请在那里提交问题。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47745762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档