Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如何从列表中的一个对象中获取两个整数_Python_List_Opencv_Raspberry Pi - Fatal编程技术网

Python:如何从列表中的一个对象中获取两个整数

Python:如何从列表中的一个对象中获取两个整数,python,list,opencv,raspberry-pi,Python,List,Opencv,Raspberry Pi,我正在尝试制作一个圆圈检测程序,该程序将在检测后控制/测试圆圈是否真的存在。我试着把圆的x和y放到一个列表中,一旦这是控制列表。对象列表是圆的每个x和y连续输入,而不是仅输入一次。然后它将与控制列表进行计数/比较ObjectList.count(ControlList[i])x和y在对象列表中出现了多少次。如果它出现超过5次,它就会画出来 if pregled == 0: # Checks if ControlList was wiped clear after 10 checks

我正在尝试制作一个圆圈检测程序,该程序将在检测后控制/测试圆圈是否真的存在。我试着把圆的x和y放到一个列表中,一旦这是控制列表。对象列表是圆的每个x和y连续输入,而不是仅输入一次。然后它将与控制列表进行计数/比较
ObjectList.count(ControlList[i])
x和y在对象列表中出现了多少次。如果它出现超过5次,它就会画出来

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
我的问题是如何从中得到x和y:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
['46101','91,86','46100','137,64','54,53','99,31','91,85','91,87']

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
第一个是x,第二个是y

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
如果pregled==0:#检查控制器是否在10次检查后清除
如果计数<11:#计数到10,则预设的集合=1
计数=计数+1
对于轮廓1中的cnt1:
#ret=cv2。匹配形状(cnt,cnt1,1,0.0)
面积=cv2。轮廓面积(cnt1)
如果面积>500:
ret=cv2。匹配形状(cnt,cnt1,1,0.0)
如果ret<0.02:
如果len(cnt1)>0:
M=cv2.力矩(cnt1)
如果M[“m00”]!=0:
cx=int(M['m10']/M['m00']
cy=int(M['m01']/M['m00']
#Conturji='('+str(cx)+','+str(cy)+')”
Conturji=str(cx)+','+str(cy)#将所有内容放入字符串中
如果Conturji不在ControlList中:#检查它是否已经在ControlList中
ControlList.append(Conturji)
打印(控制器)
`

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
输出:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
[['46', '101'], ['91', '86'], ['46', '100'], ['137', '64'], ['54',
'53'], ['99', '31'], ['91', '85'], ['91', '87']]
因此,您有一个包含2个元素列表的列表,您可以将其转换为Tuple或任何其他对象

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
如果您只想选取一个元素并将其解压缩,则可以按如下方式执行:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
x,y = x_y[0].split(",")
但是,如果您更改这一行,效率会高得多:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
Conturji=str(cx)+','+str(cy)

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
Conturji=(cx,cy)

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
元组快速高效,以后您甚至可以立即打印它们:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
tuple = (1,2)
print(tuple)
(1,2)
您可以使用该功能

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)

简单的答案是,首先决不要将它们作为字符串放入,您应该让循环将它们作为元组添加到列表中,这样就不必对其进行后期处理以获得实际输出

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
Conturji = str(cx) +','+ str(cy) # Puts everything in string
应该是

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
Conturji = cx, cy
您的输出将成为

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
[ (46, 101), (91, 86), (46,100), ...
地图

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
x_y= ['46,101', '91,86', '46,100', '137,64', '54,53', '99,31', '91,85', '91,87']
new_list = list(map(lambda x: x.split(','),x_y))
print(new_list)
或:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
但最好的办法仍然是:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
替换:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)
Conturji = str(cx) +','+ str(cy) # Puts everything in string
与:

    if pregled == 0:  # Checks if ControlList was wiped clear after 10 checks

            if count < 11: # counts to 10 the sets pregled = 1
                    count = count + 1

                    for cnt1 in contours1:

                            #ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                            area = cv2.contourArea(cnt1)

                            if area > 500:

                                  ret = cv2.matchShapes(cnt,cnt1,1,0.0)

                                  if ret < 0.02:


                                          if len(cnt1) > 0:
                                                  M = cv2.moments(cnt1)

                                                  if M["m00"] != 0:

                                                          cx = int(M['m10']/M['m00'])
                                                          cy = int(M['m01']/M['m00'])

                                                          #Conturji = '('+str(cx)+','+str(cy)+')'
                                                          Conturji = str(cx) +','+ str(cy) # Puts everything in string

                                                          if Conturji not in ControlList: # Checks if it already is in ControlList

                                                                  ControlList.append(Conturji)

                                                          print(ControlList)

你为什么一开始就用那种格式?为什么不使用两个整数的列表或元组而不是将其放入字符串中?使用元组而不是将两个坐标都塞进字符串中。谢谢您的回答!但当我想画一个圆心在x和y上的圆时,它说它必须是整数而不是整数@在ControlList:cv2.circle(img_-crop,ControlList[p],5,(0,255,0),-1)中对p使用Sayse@U9 Forward
*ControlList[p]
将其解压为两个值或
ControlList[p][0]
用于
x
ControlList[p][1]
用于
y