240x320屏幕通过layer显示问题

Viewed 212

问题描述


屏幕是240x320的,通过以下代码显示是正常的横屏
import time
from media.sensor import *
from media.display import *
from media.media import *

sensor = Sensor()
sensor.reset()
sensor.set_framesize(width=320, height=240) #
sensor.set_pixformat(Sensor.RGB565)

Display.init(30, to_ide=1, flag=Display.FLAG_ROTATION_90)

MediaManager.init()
sensor.run()

clock = time.clock()

while True:
clock.tick()
img = sensor.snapshot()
Display.show_image(img)
print("FPS:", clock.fps())

但是当用layer来显示的时候右边有一部分是重叠的,以下是代码

import gc
from media.sensor import *
from media.display import *
from media.media import *

sensor = Sensor()
sensor.reset()

display_size = [320, 240]
sensor.set_framesize(w=display_size[0], h=display_size[1], chn=CAM_CHN_ID_0)
sensor.set_pixformat(Sensor.YUV420SP, chn=CAM_CHN_ID_0)

Display.init(Display.JD9852, osd_num=1, to_ide=0)

osd_img = image.Image(320, 240, image.ARGB8888)

sensor_bind_info = sensor.bind_info(x=0, y=0, chn=CAM_CHN_ID_0)
Display.bind_layer(**sensor_bind_info, layer=Display.LAYER_VIDEO1)

MediaManager.init()
sensor.run()

while True:
osd_img.clear()
Display.show_image(osd_img)
要怎么修改
这是对应的显示
正常.jpg
不正常.jpg

硬件板卡


定制板

软件版本


micropython_v1.4-0-g6cce59c_nncase_v2.9.0

7 Answers

你好,这个是您自己添加的屏幕吗?方便发一下对应的改动吗?

需要哪方面的?配置屏幕吗?

是的,在micropython中,怎么增加的支持。

是这个吗

        elif _type == Display.JD9852:
            _width = width if width is not None else 240
            _height = height if height is not None else 320
            _flag = flag if flag is not None else Display.FLAG_ROTATION_90

            if _width == 240 and _height == 320:
                cls._panel_flag = _flag
                cls._connector_type = JD9852_MIPI_1LAN_240X320_60FPS
            elif _width == 320 and _height == 240:
                cls._connector_type = JD9852_MIPI_1LAN_240X320_60FPS
            else:
                raise ValueError(f"JD9852 unsupport {_width}x{_height}")

            _width = None
            _height = None
            _flag = None

你好,这个屏幕默认的分辨率是320x240还是240x320?

240x320

通过 flag=Display.FLAG_ROTATION_90显示成横屏的,但是在layer里配置不行

QQ图片20250930154431(1) (1).png
我发现右边部分一部分是重叠一部分是显示的左边的图像,所以整个图像应该是要往右移黄色框的距离应该就是对的了

sensor = Sensor()
sensor.reset()

display_size = [800, 480]
sensor.set_framesize(w=display_size[0], h=display_size[1], chn=CAM_CHN_ID_0)
sensor.set_pixformat(Sensor.YUV420SP, chn=CAM_CHN_ID_0)

Display.init(Display.ST7701, width=800, height=480, to_ide=1, flag=Display.FLAG_ROTATION_0)

osd_img = image.Image(800, 480, image.ARGB8888)

sensor_bind_info = sensor.bind_info(x=0, y=0, chn=CAM_CHN_ID_0)
Display.bind_layer(**sensor_bind_info, layer=Display.LAYER_VIDEO1)

MediaManager.init()
sensor.run()

while True:
osd_img.clear()
Display.show_image(osd_img)
这是st7701想竖屏显示,但是异常,应该怎么修改?

这是横屏显示的代码
sensor = Sensor()
sensor.reset()

display_size = [800, 480]
sensor.set_framesize(w=display_size[0], h=display_size[1], chn=CAM_CHN_ID_0)
sensor.set_pixformat(Sensor.YUV420SP, chn=CAM_CHN_ID_0)

Display.init(Display.ST7701, width=800, height=480, to_ide=1)

osd_img = image.Image(800, 480, image.ARGB8888)

sensor_bind_info = sensor.bind_info(x=0, y=0, chn=CAM_CHN_ID_0)
Display.bind_layer(**sensor_bind_info, layer=Display.LAYER_VIDEO1)

MediaManager.init()
sensor.run()

while True:
osd_img.clear()
Display.show_image(osd_img)
IMG20251009104012.jpg

import time, os, urandom, sys

from media.display import *
from media.media import *

# 800x480为横屏,480x800为竖屏
DISPLAY_WIDTH = ALIGN_UP(800, 16)
DISPLAY_HEIGHT = 480

def display_test():
    print("display test")

    # create image for drawing
    img = image.Image(DISPLAY_WIDTH, DISPLAY_HEIGHT, image.ARGB8888)

    # use lcd as display output
    Display.init(Display.ST7701, width = DISPLAY_WIDTH, height = DISPLAY_HEIGHT, to_ide = True)
    # init media manager
    MediaManager.init()

    try:
        while True:
            img.clear()
            for i in range(10):
                x = (urandom.getrandbits(11) % img.width())
                y = (urandom.getrandbits(11) % img.height())
                r = (urandom.getrandbits(8))
                g = (urandom.getrandbits(8))
                b = (urandom.getrandbits(8))
                size = (urandom.getrandbits(30) % 64) + 32
                # If the first argument is a scaler then this method expects
                # to see x, y, and text. Otherwise, it expects a (x,y,text) tuple.
                # Character and string rotation can be done at 0, 90, 180, 270, and etc. degrees.
                img.draw_string_advanced(x,y,size, "Hello World!,你好世界!!!", color = (r, g, b),)

            # draw result to screen
            Display.show_image(img)

            time.sleep(1)
            os.exitpoint()
    except KeyboardInterrupt as e:
        print("user stop: ", e)
    except BaseException as e:
        import sys
        sys.print_exception(e)

    # deinit display
    Display.deinit()
    os.exitpoint(os.EXITPOINT_ENABLE_SLEEP)
    time.sleep_ms(100)
    # release media buffer
    MediaManager.deinit()

if __name__ == "__main__":
    os.exitpoint(os.EXITPOINT_ENABLE)
    display_test()

用这个代码,我用JD9852的屏幕横屏竖屏显示都没有问题,但是通过layer显示摄像头画面的时候会出现上面说的问题,是不是表示屏幕的驱动是没有的问题的?

对的,屏幕驱动没问题,大概率是代码哪里写错了。

ST7701怎么通过layer竖屏显示摄像头画面,下面我贴的代码显示异常

ST7701怎么通过layer竖屏显示摄像头画面?,我通过
sensor = Sensor()
sensor.reset()

display_size = [480, 800]
sensor.set_framesize(w=display_size[0], h=display_size[1], chn=CAM_CHN_ID_0)
sensor.set_pixformat(Sensor.YUV420SP, chn=CAM_CHN_ID_0)

Display.init(Display.ST7701, osd_num=1, to_ide=0, flag=Display.FLAG_ROTATION_0)

osd_img = image.Image(480, 800, image.ARGB8888)

sensor_bind_info = sensor.bind_info(x=0, y=0, chn=CAM_CHN_ID_0)
Display.bind_layer(**sensor_bind_info, layer=Display.LAYER_VIDEO1)

MediaManager.init()
sensor.run()

while True:
osd_img.clear()
Display.show_image(osd_img)
显示的画面虽然是竖屏的,但是画面明显被拉长了,不对

sensor.set_framesize(w=display_size[0], h=display_size[1], chn=CAM_CHN_ID_0, crop = True),这样就不会有畸变了

不行,报错Traceback (most recent call last):
File "", line 10, in
File "media/sensor.py", line 1, in set_framesize
TypeError: object of type 'bool' has no len()

你用的是什么时候的固件?这个功能是在8月之后才支持的。