简体   繁体   English

具有自动启动的OpenCV的Raspberry Pi(Linux)上的应用程序

[英]Application on Raspberry Pi (Linux) with OpenCV that autostarts

I have used OpenCv within my Windows applications in the past and in this case, an application would be built and installed as a Windows Service so that it could be set to start automatically and start running. 过去,我曾在Windows应用程序中使用过OpenCv,在这种情况下,将构建并安装一个应用程序作为Windows服务,以便可以将其设置为自动启动并开始运行。 Differences are I have done these in compiled languages and we were on Windows. 区别在于我使用编译语言完成了这些操作,而我们使用的是Windows。

Now, I am playing around with porting the application to run on Linux/Raspberry Pi. 现在,我正在尝试将应用程序移植到可在Linux / Raspberry Pi上运行。 The application simply gets a video feed, does some object detection using OpenCv and then sends result via HTTP web api. 该应用程序仅获取视频供稿,使用OpenCv进行一些对象检测,然后通过HTTP Web API发送结果。

First comment before my question is (I am still getting familiar with this setup) it seems that Python is by far the language of choice for all of this. 在我提出问题之前的第一个评论是(我仍然熟悉此设置),到目前为止,Python似乎是所有这些语言的首选语言。 However, the end goal is to have this device be headless (no monitor or input devices and act like an IoT device) so I don't need or better, can't open a console and type commands. 但是,最终目标是使该设备无头(没有监控器或输入设备,并且像物联网设备一样工作),因此我不需要或更好,无法打开控制台并键入命令。

So, for the question, what is the equivalent to a Windows Service on Raspberry Pi so that my application just starts up on boot and runs as long as the device is on? 因此,对于这个问题,什么相当于Raspberry Pi上的Windows服务,以便我的应用程序仅在启动时启动并只要设备打开就可以运行? The subjective follow up question is Python still a good choice considering everything I have described above or would I be better off doing a full blown compiled app in c or c++? 考虑到我上面已经描述的一切,主观的跟进问题是Python仍然是一个不错的选择,还是用c或c ++编写完整的编译应用程序会更好吗?

Thanks! 谢谢!

If you are using Raspbian, then I would say the easiest tool il systemd (daemon) and the systemctl (shell command). 如果您使用的是Raspbian,那么我会说最简单的工具il systemd(守护程序)和systemctl(shell命令)。

In order to run your python script as a daemon (a daemon is what Windows calls "Service") is to create a configuration file named .service and put it in the /etc/systemd/system path. 为了将python脚本作为守护程序运行(Windows称为“服务”的守护程序)是创建一个名为.service的配置文件,并将其放在/ etc / systemd / system路径中。

To get an idea of how to configure the file, you can take this example: 要了解如何配置文件,可以使用以下示例:

[Unit]

Description=Your service name

[Service]

ExecStart=python <path to python script>

StandardOutput=null


[Install]

WantedBy=multi-user.target

Alias=this_script_name>.script

Hope it helps! 希望能帮助到你!

Check out Supervisor: http://supervisord.org/ . 签出Supervisor: http : //supervisord.org/ It should do what you need to do in terms of running your program on boot and restarting if it crashes, etc. 它应该执行在引导程序时运行并在崩溃时重新启动等方面所需的操作。

I don't have any experience with OpenCV, but web app frameworks like Flask ( http://flask.pocoo.org/ ) make it very easy to expose an HTTP API with minimal code. 我没有使用OpenCV的经验,但是Flask( http://flask.pocoo.org/ )这样的Web应用程序框架使使用最少的代码公开HTTP API变得非常容易。

Good luck! 祝好运!

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

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