Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Pythonda rasmni YUV ga convert qilish

0 ovoz
22 marta ko‘rilgan
so‘radi 28 noyabr Farruxnet (1,269 bal)
tahrirlandi 28 noyabr Farruxnet

Pythonda rasmni YUV ga convert qilishda muanmo bo'lyapdi github dan olgandim xatolik beryapdi shunga yordam kerak.

from PIL import Image

def yuv420_to_rgb888(width, height, yuv):

    if (width % 4) or (height % 4):
        raise Exception("width and height must be multiples of 4")
    rgb_bytes = bytearray(width*height*3)

    red_index = 0
    green_index = 1
    blue_index = 2
    y_index = 0

    for row in range(0,height):
        u_index = width * height + (row//2)*(width//2)
        v_index = u_index + (width*height)//4

        for column in range(0,width):
            Y = yuv[y_index]
            U = yuv[u_index]
            V = yuv[v_index]
            C = (Y - 16) * 298
            D = U - 128
            E = V - 128
            R = (C + 409*E + 128) // 256
            G = (C - 100*D - 208*E + 128) // 256
            B = (C + 516 * D + 128) // 256

            R = 255 if (R > 255) else (0 if (R < 0) else R)
            G = 255 if (G > 255) else (0 if (G < 0) else G)
            B = 255 if (B > 255) else (0 if (B < 0) else B)

            rgb_bytes[red_index] = R
            rgb_bytes[green_index] = G
            rgb_bytes[blue_index] = B

            u_index += (column % 2)
            v_index += (column % 2)
            y_index += 1
            red_index += 3
            green_index += 3
            blue_index += 3

    return rgb_bytes




def testConversion(source, dest):
    print("opening file")
    f = open(source, "rb")
    yuv = f.read()
    f.close()

    print("read file")
    rgb_bytes = yuv420_to_rgb888(1920,1088, yuv)

    print("finished conversion. Creating image object")

    img = Image.frombytes("RGB", (1920,1088), bytes(rgb_bytes))
    print("Image object created. Starting to save")

    img.save(dest, "PNG")
    img.close()
    print("Save completed")

if __name__ == "__main__":
    testConversion("for4.yuv", "for4.png")

XATOLIK QUYIDAGICHA:

Iltimos, saytga kiring yoki ro‘yxatdan o‘ting va shunda ushbu savolga javob berishingiz mumkin bo‘ladi.

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...