繁体   English   中英

尝试运行openalpr错误,但遇到此错误OSError:[Errno 2]没有这样的文件或目录

[英]Trying to run openalpr error but this error encounter OSError: [Errno 2] No such file or directory

我尝试运行python程序,在该程序中我想使用笔记本电脑的网络摄像头扫描车牌,但尝试运行该程序时出现此错误。 我为此使用OpenALPR和OpenCV。

我附有错误的屏幕截图。

错误图片:

以下是程序代码的链接。

import json, shlex, subprocess

class PlateReader:


    def __init__(self):
        #webcam subprocess args
        webcam_command = "fswebcam -r 640x480 -S 20 --no-banner --quiet alpr.jpg"
        self.webcam_command_args = shlex.split(webcam_command)

        #alpr subprocess args
        alpr_command = "alpr -c eu -t hr -n 300 -j alpr.jpg"
        self.alpr_command_args = shlex.split(alpr_command)


    def webcam_subprocess(self):
        return subprocess.Popen(self.webcam_command_args, stdout=subprocess.PIPE)


    def alpr_subprocess(self):
        return subprocess.Popen(self.alpr_command_args, stdout=subprocess.PIPE)


    def alpr_json_results(self):
        self.webcam_subprocess().communicate()
        alpr_out, alpr_error = self.alpr_subprocess().communicate()

        if not alpr_error is None:
            return None, alpr_error
        elif "No license plates found." in alpr_out:
            return None, None

        try:
            return json.loads(alpr_out), None
        except ValueError, e:
            return None, e


    def read_plate(self):
        alpr_json, alpr_error = self.alpr_json_results()

        if not alpr_error is None:
            print alpr_error
            return

        if alpr_json is None:
            print "No results!"
            return

        results = alpr_json["results"]

        ordinal = 0
        for result in results:
            candidates = result["candidates"]

            for candidate in candidates:
                if candidate["matches_template"] == 1:
                    ordinal += 1
                    print "Guess {0:d}: {1:s} {2:.2f}%".format(ordinal, candidate["plate"], candidate["confidence"])


if __name__=="__main__":
    plate_reader = PlateReader()
    plate_reader.read_plate()

(ps-我花了无数的时间来解决StackOverflow的代码缩进,但我做不到)

我也用过类似的代码。 只需从alpr_command = "alpr -c eu -t hr -n 300 -j alpr.jpg"此属性-t hr 并且此代码应该有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM