树莓派相机.资源不足 [英] Raspberry Pi camera. Out of resources

查看:52
本文介绍了树莓派相机.资源不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用运动传感器启动我的相机.像这样工作正常:

Trying to launch my camera with motion sensor. Works fine like this:

import RPi.GPIO as GPIO
import time
import picamera
import datetime
import os

def getFileName():
    return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")

pin = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
prevState = False
currState = False
camera = picamera.PiCamera()
while True:
    time.sleep(0.1)
    prevState = currState
    currState = GPIO.input(pin)
    if currState != prevState:
        newState = "HIGH" if currState else "LOW"
        print ("GPIO pin %s is %s" % (pin, newState))
        if currState:
            fileName = getFileName()
            print ("Starting Recording...")
            camera.start_preview()
            camera.start_recording(fileName)
            time.sleep(10)
            print (fileName)
        else:
            camera.stop_preview()
            time.sleep(1)
            camera.stop_recording()
            print ("Stopped Recording")

    else:
        print("No motions")

但后来我尝试为 Tornado 服务器定义我的函数:

But then i try to def my function for Tornado server:

def secure_on(prevState, currState):
    pin = 4
    #GPIO.setmode(GPIO.BCM)
    #GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
    #camera = picamera.PiCamera()
    time.sleep(0.1)
    prevState = currState
    #currState = GPIO.input(pin)
    if currState != prevState:
        newState = "HIGH" if currState else "LOW"
        return {'info': "GPIO pin %s is %s" % (pin, newState)}
        if currState:
            fileName = getFileName()
            print ("Starting Recording...")
            #camera.start_preview()
            #camera.start_recording(fileName)
            time.sleep(10)
            return {'info': fileName}
        else:
            #camera.stop_preview()
            time.sleep(1)
            #camera.stop_recording()
            return {'info': "Stopped Recording"}
    else:
        return {'info': "No motions"}

龙卷风:

class SecureOnHandler(tornado.web.RequestHandler):
    @gen.coroutine
    def get(self):
        result = RosPi.secure_on(prevSec, currSec)

        self.write({"info": result['info']})

然后我得到一个错误

无法启用相机组件:资源不足(内存除外)错误:tornado.access:500 GET/secure_on

"Camera component couldn't be enabled: Out of resources (other than memory) ERROR:tornado.access:500 GET /secure_on

可能导致错误的原因是什么?提前致谢!

What could be causing the error? Thanks in advance!

推荐答案

我知道这是一个老问题,但我只是想将我的解决方案发布到 Out of resources 错误,以防它可以节省一些时间和精力.

I know this is an old question but I just wanted to post my solution to the Out of resources error in case it can save someone time and effort.

我的问题是我同时初始化相机模块是两个 Python 文件(一个带有 while 循环的脚本在检测到运动时拍照,另一个脚本按需拍照).

The problem for me was that I was initializing the camera module is two Python files at the same time (a script with a while loop that took a picture when motion was detected and another script that took a picture on demand).

根据文档:https://picamera.readthedocs.io/en/release-1.13/faq.html#camera-locks-up-with-multiprocessing 您必须确保只有一个进程创建了 PiCamera 一次.

As per the documentation: https://picamera.readthedocs.io/en/release-1.13/faq.html#camera-locks-up-with-multiprocessing you must ensure that only a single process creates an instance of PiCamera at one time.

我的解决方案只是在一个函数内移动初始化相机模块,并在拍摄照片后调用 .close() 以释放进程准备好供下一个调用它的脚本使用.

My solution was simply to move initializing the camera module inside a function and call .close() after taking the picture to free up the process ready to be used by the next script that calls it.

这篇关于树莓派相机.资源不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆