image_drawing_with_custom_palette.py

# هذا العمل مرخص بموجب ترخيص MIT.
# حقوق النشر (c) 2013-2023 OpenMV LLC. جميع الحقوق محفوظة.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# مثال رسم الصور بلوحة ألوان مخصصة
#
# يوضح هذا المثال كيفية رسم الصور في ذاكرة الإطار المؤقتة بلوحة ألوان مُولَّدة مخصصة.

import csi
import image
import time

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.GRAYSCALE)  # أو GRAYSCALE...
csi0.framesize(csi.QQVGA)  # أو QQVGA...
csi0.snapshot(time=2000)

clock = time.clock()

# لوحة الألوان هي في الواقع صورة، وهذا يتيح لك استخدام عمليات الصور لإنشاء لوحات ألوان
# يجب أن تحتوي الصورة على 256 مُدخلًا، أي 256x1 أو 64x4 أو 16x16، وأن تكون بصيغة rgb565

# تهيئة ألوان مصدر لوحة الألوان في صورة
palette_source_colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 0, 255)]
palette_source_color_image = image.Image(len(palette_source_colors), 1, csi.RGB565)
for i, color in enumerate(palette_source_colors):
    palette_source_color_image[i] = color

# تحجيم الصورة إلى عرض لوحة الألوان وتنعيمها
palette = image.Image(256, 1, csi.RGB565)
palette.draw_image(
    palette_source_color_image,
    0,
    0,
    x_scale=palette.width() / palette_source_color_image.width(),
)
palette.mean(int(palette.width() / palette_source_color_image.width() / 2))

while True:
    clock.tick()

    img = csi0.snapshot()
    # الحصول على نسخة من الصورة بتدرج رمادي قبل التحويل إلى الألوان
    img_copy = img.copy()

    img.to_rgb565()

    palette_boundary_inset = int(csi0.width() / 40)
    palette_scale_x = (csi0.width() - palette_boundary_inset * 2) / palette.width()

    img.draw_image(img_copy, 0, 0, color_palette=palette)
    img.draw_image(
        palette,
        palette_boundary_inset,
        palette_boundary_inset,
        x_scale=palette_scale_x,
        y_scale=8,
    )
    img.draw_rectangle(
        (palette_boundary_inset, palette_boundary_inset, int(palette.width() * palette_scale_x), 8),
        color=(255, 255, 255),
        thickness=1,
    )

    print(clock.fps())

results matching ""

    No results matching ""