Qt Creator调用python代码处理图片结果显示

       本期是一篇Qt的实战,准备为深度学习的功能制作界面使用,所以这里需要调用python代码的功能才能实现最后python版本的深度学习处理得到的图片能在Qt上展示。

首先我们先看到python代码端,写个python代码能对输入的图片统计其RGB平均值,并返回。

from PIL import Image

def calculate_average_rgb(image_path):
    img = Image.open(image_path)
    rgb_im = img.convert('RGB')
    
    width, height = rgb_im.size
    r_total = 0
    g_total = 0
    b_total = 0
    
    for x in range(width):
        for y in range(height):
            r, g, b = rgb_im.getpixel((x, y))
            r_total += r
            g_total += g
            b_total += b
    
    total_pixels = width * height
    r_average = r_total / total_pixels
    g_average = g_total / total_pixels
    b_average = b_total / total_pixels
    
    return (r_average, g_average, b_average)

image_path = 'path_to_

你可能感兴趣的:(c++,python,开发语言,深度学习,人工智能,opencv)