0

Issue Summary

I've tried to run a python script for obtaining the nose and neck key points by running a loop over the heat maps for these key points and setting a threshold value of 200. It works fine for a single image. However, I tried modifying my script to work for the webcam and the exact same loop I used for the heat maps throws me a 'list index out of range' error. I'm struggling to understand why this is the case and how I can debug it.

Also if someone else has implemented something similar to this please let me know how you did it.

Here is a snippet of the part of my code that's throwing the error:

opWrapper = op.WrapperPython()
opWrapper.configure(params)
opWrapper.start()
start = time.time()
Process Image

print("[INFO] starting video stream...")
#vs = VideoStream(src=0).start()

video = cv2.VideoCapture(0)
while True:
    
    ret, imageToProcess = video.read()
    datum = op.Datum()
    datum.cvInputData = imageToProcess
    opWrapper.emplaceAndPop([datum])


    # Process outputs
    outputImageF = (datum.inputNetData[0].copy())[0,:,:,:] + 0.5
    outputImageF = cv2.merge([outputImageF[0,:,:], outputImageF[1,:,:], outputImageF[2,:,:]])
    outputImageF = (outputImageF*255.).astype(dtype='uint8')
    heatmaps = datum.poseHeatMaps.copy()
    heatmaps = (heatmaps).astype(dtype='uint8')
    print(heatmaps.shape)
    print(imageToProcess.shape)
    coord_nose=[]
    coord_neck=[]
    for i, j in itertools.product(range(heatmaps.shape[1]), range(heatmaps.shape[2])):
            if heatmaps[0][i][j]>200:
                print(i,j)
                coord_nose.append([j,i])
            if heatmaps[1][i][j]>200:
                coord_neck.append([j,i])
        
        

    circle = cv2.circle(outputImageF,tuple(coord_nose[0]),5,(0,0,255),-1)
    circle1 = cv2.circle(outputImageF,tuple(coord_neck[0]),5,(0,255,0),-1)
    cv2.imshow("OpenPose 1.6.0 - Tutorial Python API", outputImageF)
    end=time.time()
    print(end-start)
    
    if cv2.waitKey(1) & 0xFF == ord('q'): # press q to quit program
        video.release()
        cv2.destroyAllWindows()

The loop which is throwing the error:

    for i, j in itertools.product(range(heatmaps.shape[1]), range(heatmaps.shape[2])):
            if heatmaps[0][i][j]>200:
                print(i,j)
                coord_nose.append([j,i])
            if heatmaps[1][i][j]>200:
                coord_neck.append([j,i])

Console Output (with error):

(25, 176, 320) <-- shape of heatmaps 
(720, 1280, 3) <--- shape of my input image
list index out of range
Vanya A
  • 1
  • 1
  • 2

0 Answers0