Home > OS >  How do I retrieve coordinates from a list containing other items?
How do I retrieve coordinates from a list containing other items?

Time:03-04

So I have a list called 'masterStruc' which contains several items. I am also storing coordinates in this list for later use. However, when I try to retrieve the coordinates from the list I am getting a "TypeError: 'int' object is not subscriptable". Is there anyway I can get the values from the list without getting this error? In the list I have color, some contour data from the approxPolyDP function, the contour area and the x and y coordinates.

#masterStruc appends the relevant data
masterStruc.append([x, approxCurve, contArea, cX, cY])
for z in range(len(masterStruc)):
    #Drawing contours on the source image
    cv2.drawContours(srcImg, [masterStruc[z][1]], 0, drawColor[masterStruc[z][0]], 2)
    cv2.circle(srcImg, masterStruc[z[3][4]], 5, (255, 255, 255), -1)

Any assistance is appreciated

CodePudding user response:

Thanks for the responses. It turns out I had two errors in my code. The first being that I should have encased masterStruc in brackets. The second being that I could not pass x and y coordinates using the list because the at some index there was a wrong type. I instead solved this error by passing the coordinates to a variable and then using that as a parameter.

x = masterStruc[z][3]
y = masterStruc[z][4]
cv2.circle(srcImg, (x, y), 5, (0, 0, 0), -1)

CodePudding user response:

Why is masterStruc[z][1] in brackets [] ?

Perhaps the type error is there

  • Related