Touch Designer Open CV Error cv2 has no attribute COLOR_RGB2Gray

59 views Asked by At

Im new to touch designer and have been doing this tutorial by Scott Allen on using open cv with touch for multi face tracking.

I have followed as best as I can but keep getting error messages in my script, from what I can tell I have copied his exactly.

the error code I get is as followed.

"Error: Traceback (most recent call last): File "/project1/script1_callbacks", line 10 in onCook AttributeError: module 'cv2' has no attribute 'COLOR_RGB2Gray' (/project/Script1_callbacks)

Does anyone have an idea where I've gone wrong? and how to fix this?

All the best, Barney

TUTORIAL LINK https://www.youtube.com/watch?v=tEksriIknZE&ab_channel=ScottAllen

Initially i thought i may have to install open cv seperately from what touch has installed anyway. So i did that using VS Code.

checked spellings.

redone the tuorial from scratch

import cv2
import numpy as np

face_cascade = cv2.CascadeClassifier('data/raw.githubusercontent.com_opencv_opencv_master_data_haarcascades_haarcascade_frontalface_default.xml')

def onCook(scriptOp):
    frame = op('SRC_ANALYZE').numpyArray()
    scriptOp.copyNumpyArray(frame)

    gray = cv2.cvtColor(frame, cv2.COLOR_RGB2Gray)
    gray = gray * 255.0
    gray = gray.astype(np.unit8)
    gray_invert = np.flipud(gray)

    faces = face_cascade.detectMultiscale(gray_invert)

    scr = op('script2')
    scr.lock = True
    scr.clear()

    tx = scr.appendChan('tx')
    ty = scr.appendChan('ty')
    tw = scr.appendChan('tw')
    th = scr.appendChan('th')


    scr.numSamples = len(faces)

    SRC_ANALYZE_W = op('SRC_ANALYZE').width
    SRC_ANALYZE_H = op('SRC_ANALYZE').height
    aspect = SRC_ANALYZE_W / SRC_ANALYZE_H

    if len(faces) > 0:
        for i in range(scr.numSamples):
            x = faces[i][0]
            y = faces[i][1]
            w = faces[i][2]
            h = faces[i][3]
            tx[i] = (x + w / 2) / SRC_ANALYZE_W
            ty[i] = (- (y + h / 2) / SRC_ANALYZE_H + 1) / aspect
            tw[i] = w / SRC_ANALYZE_W
            th[i] (h / SRC_ANALYZE_W) / aspect

    scr.lock = False



    return

0

There are 0 answers