我怎样才能摆脱健身分数 0?

问题描述

我的遗传算法有一个 HSV 图像作为输入,当我编译代码时,我有以下警告

RuntimeWarning: overflow encountered in ubyte_scalars

警告是因为我想计算两个像素之间的距离

def HSV_binaryList(imageSubMatrix,threshold):
    weight,height,channels = imageSubMatrix.shape
    binaryRule = []
    centerPixel = imageSubMatrix[1][1]
    h0,s0,v0 = centerPixel[0],centerPixel[1],centerPixel[2]
    for i in range(weight):
        for j in range(height):
            h1,s1,v1 = imageSubMatrix[i][j][0],imageSubMatrix[i][j][1],imageSubMatrix[i][j][2]
            dh = abs(h1 - h0) / 180.0
            ds = abs(h1 - h0) / 255.0
            dv = abs(h1 - h0) / 255.0
            distance = math.sqrt(dh ** 2 + ds ** 2 + dv ** 2) / math.sqrt(3)
            if distance > threshold:
                binaryRule.append(1)
            else:
                binaryRule.append(0)
    return binaryRule

imageSubMatrix 是来自 HSV 图像的 3*3 区域,阈值是介于 0 和 1 之间的

我试图更正警告,我阅读了图像并更改了 dtype。此更改后,适应度分数为 0。在更改像素类型 (dtype='float64') 之前,我的适应度分数很好。

startimage = cv2.imread("image1.jpg")
dst = cv2.fastNlMeansDenoisingColored(startimage,None,10,7,21)
resized = cv2.resize(dst,(256,256))
initimageHSV = numpy.array(cv2.cvtColor(resized,cv2.COLOR_BGR2HSV),dtype='float64')

我可以在不影响体能得分的情况下去掉警告吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)