嵌入式技术论坛
直播中

李霞

8年用户 1341经验值
私信 关注
[经验]

使用柿饼M3玩了把无线投屏器

准备工作,柿饼派1块,python2.7,opencv2环境.

彩屏投屏助手py,PC端运行,依赖opencv.

while True:

image = pyautogui.screenshot(region=[0,0,1920,1080]) # x,y,w,h

image.save('screenshot1.bmp')

image = cv2.imread('screenshot1.bmp')

frame1 = cv2.resize(image,(480, 272),interpolation=cv2.INTER_CUBIC)

cv2.imwrite('screenshot.bmp', frame1)

cv2.imshow('img', frame1)

if cv2.waitKey(1)& 0xFF == ord("q"):

server.socket.close()

break

运行服务器

python -m SimpleHTTPServer 8000

柿饼派M3运行代码

f52611ed28accaf1ea53c9f7cf234c23_32df69e5ac952931ec35ee55aa3dd778.jpg

include

include

include “string.h”

include “nes_common.h”

include “defe.h”

include “debe.h”

include

define DBG_ENABLE

define DBG_SECTION_NAME “web.cap”

ifdef WEBCLIENT_DEBUG

define DBG_LEVEL DBG_LOG

else

define DBG_LEVEL DBG_INFO

endif / WEBCLIENT_DEBUG /

define DBG_COLOR

include

define WEBCLIENT_HEADER_BUFSZ 4096

define WEBCLIENT_RESPONSE_BUFSZ 480*3

define WEBCLIENT_URI

struct layer_info info;

static void cap_lcd_init(void)

{

rt_memset(&info, 0, sizeof(struct layer_info));

info.index = LAYER1;

info.pipe = PIPE1;

info.alpha_enable = 0;

info.alpha_value = 0;

info.x = 0;

info.y = 0;

info.width = 480;

info.height = 272;

info.format = COLOR_ARGB8888;

/* addr from yuv ctrl */

info.type = LAYER_TYPE_RGB;

info.buffer_addr = 0x81800000;

/* add layer */

tina_debe_layer_add(DEBE, &info);

tina_debe_layer_visible(DEBE, LAYER1);

}

static void rgb888_to_rgba888(unsigned char frame_buf, unsigned char ptr)

{

for(int i=0; i<480; i++)

{

frame_buf[i4] = ptr[i3];

frame_buf[i4+1] = ptr[i3+1];

frame_buf[i4+2] = ptr[i3+2];

}

}

static int web_client_getimage(void)

{

unsigned int * frame_buf = 0x81800000;

int fd = -1, rc = WEBCLIENT_OK;

size_t offset;

int length, total_length = 0;

unsigned char *ptr = RT_NULL;

struct webclient_session* session = RT_NULL;

int resp_status = 0;

static int init = 0;

if(init = 0)

memset(frame_buf, 0, 4802724);

init = 1;

session = webclient_session_create(WEBCLIENT_HEADER_BUFSZ);

if(session == RT_NULL)

{

rc = -WEBCLIENT_NOMEM;

goto __exit;

}

if ((resp_status = webclient_get(session, WEBCLIENT_URI)) != 200)

{

LOG_E("get file failed, wrong response: %d (-0x%X).", resp_status, resp_status);

rc = -WEBCLIENT_ERROR;

goto __exit;

}

ptr = (unsigned char *) web_malloc(WEBCLIENT_RESPONSE_BUFSZ);

if (ptr == RT_NULL)

{

LOG_E("get file failed, no memory for response buffer.");

rc = -WEBCLIENT_NOMEM;

goto __exit;

}

length = webclient_read(session, ptr, 54);

// LOG_RAW("0 %08x \n", frame_buf);

frame_buf += 480*271;

// LOG_RAW("1 %08x \n", frame_buf);

if (session->content_length < 0)

{

while (1)

{

length = webclient_read(session, ptr, WEBCLIENT_RESPONSE_BUFSZ);

if (length > 0)

{

// write(fd, ptr, length);

// rgb888_to_rgba888(frame_buf, ptr);

*frame_buf -= 480;

total_length += length;

LOG_RAW(">%d ", length);

}

else

{

break;

}

}

}

else

{

for (offset = 0; offset < (size_t) session->content_length;)

{

length = webclient_read(session, ptr,

session->content_length - offset > WEBCLIENT_RESPONSE_BUFSZ ?

WEBCLIENT_RESPONSE_BUFSZ : session->content_length - offset);

if (length > 0)

{

// write(fd, ptr, length);

rgb888_to_rgba888(frame_buf, ptr);

total_length += length;

frame_buf -= 480;

// LOG_RAW("* %08x ", frame_buf);

}

else

{

break;

}

offset += length;

}

}

if (total_length)

{

LOG_D("save %d bytes.", total_length);

}

__exit:

// if (fd >= 0)

// {

// close(fd);

// }

if (session != RT_NULL)

{

webclient_close(session);

}

if (ptr != RT_NULL)

{

web_free(ptr);

}

return rc;

}

static void win_cap_thread(void *parameter)

{

cap_lcd_init();

while(1)

{

web_client_getimage();

rt_kprintf("win cap\n");

}

}

void win_cap_demo(void)

{

int tid = rt_thread_create("vnes", win_cap_thread, 0, 2048*16, 18, 20);

if (tid != RT_NULL)

rt_thread_startup(tid);

return 0;

}

MSH_CMD_EXPORT(win_cap_demo, win_cap_demo);

运行视频

爽后感,好玩,帧率低,装A和C之间还可以,暂没有发现有什么实际用途。

原作者:14510690

更多回帖

发帖
×
20
完善资料,
赚取积分