Python,OpenCv如何加速?

时间:2018-05-21 14:17:52

标签: python opencv

根据我的代码,我可以检查大约10-15 FPS。 图像非常复杂。

如何提高代码的速度? 线程?我该怎么把这个帖子放进去?以及如何:)

代码

thresh = cv2.adaptiveThreshold(
    image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C ,cv2.THRESH_BINARY,11,5
)

花了很多时间...... 我不认为如果我没有它,我怎么能在线程中处理图像... 因此,当我将来自frame-> from for循环的图像时,该线程将起作用。 我必须在外部的therad中有一些工作.... 所以我认为它不会对我有所帮助。还是mayby?

from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
from datetime import datetime
import io
from array import *
import thread
image=0
thresh=0
t_start=0
t_end=0
start=0
linie1=0
linie2=0
a=0
b=0
tablica=array('i',[0,0,0,0,0,0,0,0,0,0])

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (1024, 64)
camera.framerate = 60
rawCapture = PiRGBArray(camera, size=(1024, 64))
time.sleep(1)

for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):

    image = frame.array
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    cv2.imshow('oryginal',image)
    thresh = cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C ,cv2.THRESH_BINARY,11,5)
    image = image[10:20,0:1024 ]
    _, contours, hierarchy=cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    linie2=len(contours)

    print('Number of lines:', linie2)

    cv2.imshow('thresh',thresh)

    # clear the stream in preparation for the next frame
    rawCapture.truncate(0)

    a+=1
    b+=1
    print('b: ',b)
    key = cv2.waitKey(1) & 0xFF

    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break

然后你的帮助

0 个答案:

没有答案