示例#1
0
    def frames():
        with picamera.PiCamera() as camera:
            # let camera warm up
            # camera = PiCamera()
            camera.resolution = (320, 240)
            camera.framerate = 32
            camera.rotation = 180

            # rawCapture = PiRGBArray(camera, size=(320, 240))
            # time.sleep(2)

            # stream = io.BytesIO()
            rawCapture = PiRGBArray(camera, size=(320, 240))
            start_time = time.time()
            fpscount = 0
            Vilib.cdf_flag = True
            Vilib.hdf_flag = True
            Vilib.color_change('blue')
            print(cv2.useOptimized())
            cv2.setUseOptimized(True)
            print(cv2.useOptimized())
            for _ in camera.capture_continuous(rawCapture,
                                               format="bgr",
                                               use_video_port=True):
                # return current frame
                # stream.seek(0)
                img = _.array
                # img = frame.array
                t1 = cv2.getTickCount()
                img = Vilib.color_detect_func(img)
                img = Vilib.human_detect_func(img)
                t2 = cv2.getTickCount()
                print(round((t2 - t1) / cv2.getTickFrequency(), 3))
                # yield stream.read()
                yield cv2.imencode('.jpg', img)[1].tobytes()
                rawCapture.truncate(0)
示例#2
0
from vilib import Vilib
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (320, 240)
camera.framerate = 32
camera.rotation = 180
rawCapture = PiRGBArray(camera, size=(320, 240))

# allow the camera to warmup
time.sleep(0.1)
start_time = time.time()
fpscount = 0
# capture frames from the camera
Vilib.cdf_flag = True
Vilib.hdf_flag = True
Vilib.color_change('blue')
print(cv2.useOptimized())
cv2.setUseOptimized(True)
print(cv2.useOptimized())
for frame in camera.capture_continuous(rawCapture,
                                       format="bgr",
                                       use_video_port=True):
    # grab the raw NumPy array representing the image, then initialize the timestamp
    # and occupied/unoccupied text
    img = frame.array
    t1 = cv2.getTickCount()
    img = Vilib.color_detect_func(img)
    img = Vilib.human_detect_func(img)
    t2 = cv2.getTickCount()
    print(round((t2 - t1) / cv2.getTickFrequency(), 3))
    # cv2.imshow("Frame", image)
示例#3
0
from flask_camera import web_camera_start
from camera import Camera
import time
import threading
from vilib import Vilib

Vilib.cdf_flag = True
# Vilib.hdf_flag = True
Vilib.color_change('red') 


# def forever_threading():
#     while True:
#         forever()

def forever():
    last_time = time.time()
    time.sleep(1)
    sub_time = time.time() - last_time
    print(sub_time)

if __name__ == '__main__':
    Vilib.threading_start_with(web_camera_start,forever)
    while True:
        print('end')
    
    # t1 = threading.Thread(target=web_camera_start)  #Thread是一个类,实例化产生t1对象,这里就是创建了一个线程对象t1
    # t1.start() #线程执行
    # t2 = threading.Thread(target=forever_threading) #这里就是创建了一个线程对象t2
    # t2.start()