openCL cv2.UMat对象不可迭代

时间:2018-08-20 15:51:36

标签: python opencv opencl odroid

实际上我真的不了解如何使用此T-API opencl,并且在文档中还是新手 https://www.learnopencv.com/opencv-transparent-api/

使用cv2.UMat到.image文件,然后读取它。在我的问题中,我想在reconizer.predict行中使用opencl T-API,因为图像是在流式传输相机时获取/处理的

recognizer = cv2.face.LBPHFaceRecognizer_create()
#colec = cv2.face.MinDistancePredictCollector()
recognizer.read("trainer_data_array.yml")

labels = {"persons_name":0}
with open("labels.pickle", "rb") as f:
    og_labels = pickle.load(f)
    labels = {v:k for k,v in og_labels.items()}


cap = cv2.VideoCapture(0)

while(True):
    #video cap
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)

    for (x,y,w,h) in faces:
        #print(x,y,w,h)
        roi_gray = gray[y:y+h, x:x+w]
        roy_color = frame[y:y+h, x:x+w]

        #recognize how?

        id_ , conf = recognizer.predict(roi_gray) #some error, some say cuz its opencv 3.1.0 bug 
                                                                #solution : up opencv to 3.3 or just use MinDistancePredictCollector(...)
        if conf>=45 and conf<=85:
            print(idppl)
            print(labels[idppl])
            font = cv2.FONT_HERSHEY_SIMPLEX
            name = labels[idppl]
            color = (255,255,255)
            stroke = 2
            cv2.putText(frame,name,(x,y),font,1,color,stroke,cv2.LINE_AA)
        elif conf > 85:
            print("unknown")

如果只是像id_ , conf = cv2.UMat(recognizer.predict(roi_gray))那样简单地写,有人可以帮我怎么做 它给我错误cv2.UMat' object is not iterable

在没有T-API的情况下,此行程序仍然可以提供良好的帧速率,但是在进行许多修改或实现/过程后,当检测/识别人脸时,它将以低帧速率运行。

这就是我为什么要使用openCl的原因,所以当它在gpu中运行时,mybe会给我一个相当不错的帧速率

0 个答案:

没有答案