Python Can';在单个MSER区域的集合中进行迭代时,图像是空白的。

Python Can';在单个MSER区域的集合中进行迭代时,图像是空白的。,python,arrays,opencv,numpy,mser,Python,Arrays,Opencv,Numpy,Mser,我有一个脚本,可以收集照片中的所有MSER区域: import numpy as np import cv2 import sys import matplotlib.pyplot as plt imp1 = sys.argv[1] minA = int(sys.argv[2]) maxA = int(sys.argv[3]) minD = float(sys.argv[4]) try: als = str(sys.argv[5]) except IndexError:

我有一个脚本,可以收集照片中的所有MSER区域:

import numpy as np
import cv2
import sys
import matplotlib.pyplot as plt

imp1 = sys.argv[1]
minA = int(sys.argv[2])
maxA = int(sys.argv[3])
minD = float(sys.argv[4])

try:
        als = str(sys.argv[5])
except IndexError:
        als = False

img1 = cv2.imread(imp1)


PARAMS = {'_delta':5, '_min_area': minA, '_max_area': maxA, '_min_diversity': minD}

mser = cv2.MSER(**PARAMS)
gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
vis = img1.copy()


regions = mser.detect(gray, None)
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]


print "Regions: " + str(type(regions))
print "Region Number: " + str(len(regions))
print "Hulls: " + str(type(hulls))
print "Hull Number: " + str(len(hulls))



if als == "True":
        rc = 1
        for i in hulls:
            tl = str(i.tolist())

            a = tl.replace("]], [[", "], [")
            b = a.replace("[[", "[")
            nl = b.replace("]]]", "]]")

            print "Hull  Count: " + str(rc)
            print "Hull Number: {} - {}".format(rc,  str(nl))
            print ""
            rc += 1
而且运行良好,没有问题:

Hull  Count: 617
Hull Number: 617 - [[397, 1773], [360, 1775], [356, 1775], [352, 1774], [350, 1773], [349, 1772], [349, 1766], [361, 1683], [362, 1677], [369, 1677], [370, 1678], [397, 1771]]

Hull  Count: 618
Hull Number: 618 - [[2653, 1978], [2652, 1979], [2627, 1979], [2621, 1977], [2624, 1973], [2627, 1970], [2630, 1968], [2632, 1967], [2636, 1967], [2647, 1974]]

Hull  Count: 619
Hull Number: 619 - [[2660, 1977], [2658, 1979], [2655, 1980], [2654, 1980], [2627, 1979], [2615, 1976], [2618, 1974], [2630, 1967], [2632, 1966], [2636, 1966]]
然而,当我试图在OpenCV中将这些转换为多段线时,我只会得到无限的numpy错误。然后,我尝试变得更简单,并简单地迭代各个外壳:

regions = mser.detect(gray, None)
hulls = [cv2.convexHull(p.reshape(-1, 1, 2)) for p in regions]

nl = 1
for i in hulls:

    print "I Type: " + str(type(i))
    print "I Number: " + str(nl)
    print "I Length: " + str(len(i))
    print "I Raw: " + str(i)

    cv2.polylines(vis, i, 2, (0, 255, 0))
    h = cv2.cvtColor(vis, cv2.COLOR_BGR2RGB)

    plt.imshow(h)
    plt.title('MISER Regions')
    plt.show()

    nl += 1

但这只给了我66张空白图片(即:普通图片),而我应该得到66张左右的图片,每张都有一个绿色的MSER覆盖。我不知道麻烦是从哪里来的。有人能帮我吗?

你能上传正在使用的图像吗?你能上传正在使用的图像吗?