利用framebuffer,命令行显示图片
上代码
import fcntl
import struct
import mmap
import contextlib
import os
import time
import numpy as np
import cv2 src = cv2.imread('./1.bmp', cv2.IMREAD_COLOR)
img = src#[0:100, 0:400]
print img.shape with open('/dev/fb0', 'r+b') as fbfd:
fb_fix_screeninfo = struct.pack('16sLIIIIIIIILIIHHH',
'',
0L, 0,0,0,0,0,0,0,0,
0L, 0, 0, 0, 0, 0)
'''
struct fb_fix_screeninfo {
char id[16]; /* identification string eg "TT Builtin" */
unsigned long smem_start; /* Start of frame buffer mem */
/* (physical address) */
__u32 smem_len; /* Length of frame buffer mem */
__u32 type; /* see FB_TYPE_* */
__u32 type_aux; /* Interleave for interleaved Planes */
__u32 visual; /* see FB_VISUAL_* */
__u16 xpanstep; /* zero if no hardware panning */
__u16 ypanstep; /* zero if no hardware panning */
__u16 ywrapstep; /* zero if no hardware ywrap */
__u32 line_length; /* length of a line in bytes */
unsigned long mmio_start; /* Start of Memory Mapped I/O */
/* (physical address) */
__u32 mmio_len; /* Length of Memory Mapped I/O */
__u32 accel; /* Indicate to driver which */
/* specific chip/card we have */
__u16 capabilities; /* see FB_CAP_* */
__u16 reserved[2]; /* Reserved for future compatibility */
};
'''
fb_fix_screeninfo = fcntl.ioctl(fbfd, 0x4602, fb_fix_screeninfo)
fb_fix_screeninfo = struct.unpack('16sLIIIIIIIILIIHHH', fb_fix_screeninfo)
lineLength = fb_fix_screeninfo[8] fb_var_screeninfo = struct.pack('IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII',
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
'''
struct fb_bitfield {
__u32 offset; /* beginning of bitfield */
__u32 length; /* length of bitfield */
__u32 msb_right; /* != 0 : Most significant bit is */
/* right */
};
struct fb_var_screeninfo {
__u32 xres; /* visible resolution */
__u32 yres;
__u32 xres_virtual; /* virtual resolution */
__u32 yres_virtual;
__u32 xoffset; /* offset from virtual to visible */
__u32 yoffset; /* resolution */ __u32 bits_per_pixel; /* guess what */
__u32 grayscale; /* 0 = color, 1 = grayscale, */
/* >1 = FOURCC */
struct fb_bitfield red; /* bitfield in fb mem if true color, */
struct fb_bitfield green; /* else only length is significant */
struct fb_bitfield blue;
struct fb_bitfield transp; /* transparency */ __u32 nonstd; /* != 0 Non standard pixel format */ __u32 activate; /* see FB_ACTIVATE_* */ __u32 height; /* height of picture in mm */
__u32 width; /* width of picture in mm */ __u32 accel_flags; /* (OBSOLETE) see fb_info.flags */ /* Timing: All values in pixclocks, except pixclock (of course) */
__u32 pixclock; /* pixel clock in ps (pico seconds) */
__u32 left_margin; /* time from sync to picture */
__u32 right_margin; /* time from picture to sync */
__u32 upper_margin; /* time from sync to picture */
__u32 lower_margin;
__u32 hsync_len; /* length of horizontal sync */
__u32 vsync_len; /* length of vertical sync */
__u32 sync; /* see FB_SYNC_* */
__u32 vmode; /* see FB_VMODE_* */
__u32 rotate; /* angle we rotate counter clockwise */
__u32 colorspace; /* colorspace for FOURCC-based modes */
__u32 reserved[4]; /* Reserved for future compatibility */
};'''
fb_var_screeninfo = fcntl.ioctl(fbfd, 0x4600, fb_var_screeninfo)
fb_var_screeninfo = struct.unpack('IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII', fb_var_screeninfo) screen_x = fb_var_screeninfo[0]
screen_y = fb_var_screeninfo[1]
bitPerPix = fb_var_screeninfo[6]
print("%d*%d, %dbpp" %(fb_var_screeninfo[0], fb_var_screeninfo[1], fb_var_screeninfo[6])) screensize = fb_var_screeninfo[0] * fb_var_screeninfo[1] * fb_var_screeninfo[6] / 8
print 'screensize=' + str(screensize) with contextlib.closing(mmap.mmap(fbfd.fileno(), screensize, flags=mmap.MAP_SHARED,
access=mmap.ACCESS_WRITE)) as fbp: ## print fbp.size()
loc = 0
linex = 0
for y in range(img.shape[0]):
for x in range(img.shape[1]): loc = (y*lineLength) + (x*bitPerPix/8)
fbp[loc] = chr(img[y][x][0])
fbp[loc+1] = chr(img[y][x][1])
fbp[loc+2] = chr(img[y][x][2])
fbp[loc+3] = chr(255)
##
## r = fbp.flush() ## time.sleep(3)
资料
获取framebuffer设备信息.ioctl(int fb,FBIOGET_FSCREENINFO,&finfo);
ioctl函数是实现对设备的信息获取和设定,第一个参数为文件描述符,第二个参数为具体设备的参数,对于framebuffer,参数在linux/fb.h中定义的。
#define FBIOGET_VSCREENINFO 0x4600 //获取设备无关的数据信息fb_var_screeninfo
#define FBIOPUT_VSCREENINFO 0x4601 //设定设备无关的数据信息
#define FBIOGET_FSCREENINFO 0x4602 //获取设备无关的常值信息fb_fix_screeninfo
#define FBIOGETCMAP 0x4604 //获取设备无关颜色表信息
#define FBIOPUTCMAP 0x4605 //设定设备无关颜色表信息
#define FBIOPAN_DISPLAY 0x4606
#define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor)
第三个参数是存放信息的结构体或者缓冲区
利用framebuffer,命令行显示图片的更多相关文章
- 如何使用ros命令行显示图片
rosrun image_view image_view image:=[TOPIC] 注意:每次只能显示一个UI.不能在一条命令中订阅多个节点.
- FrameBuffer系列 之 显示图片
摘自:http://blog.csdn.net/luxiaoxun/article/details/7622988 #include <unistd.h> #include < ...
- 其他综合-CentOS 7 命令行显示优化
CentOS 7 命令行显示优化 1.实验描述 通过 CentOS 7.6 的显示优化,为实现命令行显示提供良好视觉体验. [基于此文章的环境]点我快速打开文章 2.实验环境 使用软件的版本:VMwa ...
- windows下cmd命令行显示UTF8字符设置(CHCP命令)
本文由 www.169it.com 收集整理 在中文Windows系统中,如果一个文本文件是UTF-8编码的,那么在CMD.exe命令行窗口(所谓的DOS窗口)中不能正确显示文件中的内容.在默认情况下 ...
- SSH Secure Shell Client连接Linux 命令行显示中文乱码问题 和oracle 查询数据中文乱码问题
一.SSH Secure Shell Client连接Linux 命令行显示中文乱码问题 linux 设置系统语言 修改 /etc/sysconfig/i18n 文件,如 LANG="en_ ...
- sublime将python的运行结果在命令行显示
sublime将python的运行结果在命令行显示 为什么这么折腾? 因为每次查看输出结果都要上下拖动窗口,很烦. 将build system修改为 { "cmd": [" ...
- MYSQL 命令行显示乱码 解决方案
中文乱码是因为编码集不支持,所以要改变编码 先查看下设置的编码 使用如下命令 show variables like 'character%'; 在 mysql.conf (Ubuntu mysql5 ...
- myeclipse web servelet调试输入的中文在TOMCAT服务器的命令行显示为????
B 问题:myeclipse web servelet调试输入的中文在TOMCAT服务器的命令行显示为???? 解决:调整JSP页面编码:gb2312--->utf-8
- cmd命令行显示中文乱码
cmd命令行显示中文乱码多数是由于字符编码不匹配导致. 1.查看cmd编码方式 方法一.打开cmd,输入chcp命令回车(显示默认编码:活动代码页:936指GBK) 方法二.打开cmd在标题栏单击鼠标 ...
随机推荐
- Netty4.0 用户指南
原文链接http://netty.io/wiki/user-guide-for-4.x.html 前言 Nowadays we use general purpose applications or ...
- html小知识,怎么实现一个td占据2行
<table border="1" width="100%"> <tr> <td rowspan="2"> ...
- jquery相冊图片来回选择
<!DOCTYPE HTML> <html> <head> <meta charset="UTF-8"> <script sr ...
- 聚合数据Android SDK 12306火车票查询订票演示示例
1.聚合SDK是聚合数据平台,为移动开发者提供的免费数据接口.使用前请先到聚合平台(http://www.juhe.cn/)注册,申请相关数据. 2.下载聚合数据SDK,将开发包里的juhe_sdk_ ...
- svn:冲突(<<<<<<.mine ==== >>>>>>.xxxx)
http://blog.csdn.net/u014000377/article/details/50605895 在svn更新文件时会产生有冲突的文件,一般有两种解决办法: 1.更新文件之前直接查看对 ...
- c# 访问Mysql
下载Connector/Net驱动程序,并安装. 通过MySQLConnection对象来连接数据库,连接MySQL的程序的最前面需要引用MySql.Data.MySqlClient. using M ...
- 在C#中怎样推断线程当前所处的状态
在C#中怎样推断线程当前所处的状态 老帅 在C#中.线程对象Thread使用ThreadState属性指示线程状态.它是带Flags特性的枚举类型对象. ThreadState 为线 ...
- AspectJ学习笔记2-Eclipse中AspectJ插件AJDT的正确安装方法
接着之前一篇日志. 这个事情也挺无语的.简单记录一下. 在这里:http://www.eclipse.org/ajdt/ 能够下载最新的Eclipse Plugin.下载解压之后,一般来说.直接把解压 ...
- HBase——完全分布
实际上,在真实环境中你需要使用完全分布配置完整测试HBase.在一个分布式配置中,集群有多个节点,每个节点运行一个或多个HBase守护进程.其中包括主Master和备份Master实例,多个Zooke ...
- 请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但是与"aa.a"和"ab*a"均不匹配
// test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...