我们如何将Mat从opencv传递到tensorflowtf.image.ssim_多尺度?

2024-09-28 18:58:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我用opencvpython得到了一些视频帧,可以将其转换成灰度。在

现在我想做一些类似的事情来计算ssim_多尺度

    i1 = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    i2 = cv2.cvtColor(frame2,cv2.COLOR_BGR2GRAY)
    i1 = np.array(i1, dtype=np.float64)
    i2 = np.array(i2,dtype=np.float64)
    print(tf.image.ssim_multiscale(i1,i2,255))

但我有个错误

shape1 = img1.get_shape().with_rank_at_least(3). AttributeError: 'numpy.ndarray' object has no attribute 'get_shape'

我已经检查了np.数组它有get_shape属性。如何将Mat传递到ssim_multiscale参数?在

^{pr2}$

Tags: getnparraycv2colorshapedtypefloat64
1条回答
网友
1楼 · 发布于 2024-09-28 18:58:13

终于找到了答案

while(cap.isOpened()&cap2.isOpened()):
ret, frame = cap.read()
ret2,frame2 = cap2.read()

if ret & ret2:
    a = np.asarray(frame)
    a1=tf.image.convert_image_dtype(a, tf.float32)

    b = np.asarray(frame2)
    b1=tf.image.convert_image_dtype(b, tf.float32)

    test= tf.image.ssim_multiscale(a1,b1,255)
    sess = tf.Session()
    tfssim = sess.run(test)
    print(' tf ms-ssim: '+format(tfssim))
    the_file.write(' tf ms-ssim: '+format(tfssim))
    if(tfssim<1):
        caltfssimnosie+=1
        print(' *tf ms-ssim err')
        the_file.write('  *tf ms-ssim err')
    sess.close

如果使用print函数打印ms ssim值,它将显示奇怪的错误

相关问题 更多 >