1.list转RGB图
import cv2
import numpy as np
#
img_list = [[[255, 0, 53], [255, 255, 51], [49, 51, 0], [49, 255, 51], [49, 255, 51], [255, 255, 255], [255, 51, 0], [255, 0, 53],
[255, 0, 53], [49, 51, 0], [51, 0, 54], [0, 54, 55], [255, 51, 0], [49, 255, 51], [255, 51, 0], [51, 0, 53],
[51, 0, 53], [255, 51, 0], [255, 51, 0], [255, 0, 53], [255, 51, 0], [255, 51, 51], [49, 255, 51], [255, 51, 0],
[49, 51, 0], [51, 0, 53], [0, 53, 54], [255, 51, 0], [255, 0, 0], [51, 0, 53], [51, 0, 53], [255, 51, 0],
[49, 255, 51], [255, 49, 255], [49, 51, 51], [255, 0, 0], [255, 51, 0], [49, 255, 255], [255, 49, 49], [255, 49, 255],
[53, 55, 57], [0, 54, 55], [51, 0, 53], [51, 0, 53], [255, 51, 53],[255, 0, 53], [255, 255, 51], [49, 51, 0],
[49, 255, 51], [49, 255, 51], [255, 255, 255], [255, 51, 0], [255, 0, 53], [255, 0, 53], [49, 51, 0], [51, 0, 54],
[0, 54, 55], [255, 51, 0], [49, 255, 51], [255, 51, 0], [51, 0, 53], [51, 0, 53], [255, 51, 0], [255, 51, 0],
[255, 0, 53], [255, 51, 0], [255, 51, 51], [49, 255, 51], [255, 51, 0], [49, 51, 0], [51, 0, 53], [0, 53, 54],
[255, 51, 0], [255, 0, 0], [51, 0, 53], [51, 0, 53], [255, 51, 0], [49, 255, 51], [255, 49, 255], [49, 51, 51],
[255, 0, 0], [255, 51, 0], [49, 255, 255], [255, 49, 49], [255, 49, 255], [53, 55, 57], [0, 54, 55], [51, 0, 53],
[51, 0, 53], [255, 51, 53]]]
column_num = 1000
img_list = img_list*column_num
print("显示一个RGB彩色图像,‘行’为:" + str(len(img_list[0])) + "个像素, 而‘列’为 "+ str(column_num) + "个像素的图像")
img = np.asarray(img_list, dtype=np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)
while True:
cv2.imshow("lena", img)
cv2.waitKey(100)
打印输出
显示一个RGB彩色图像,‘行’为:90个像素, 而‘列’为 1000个像素的图像
显示输出
2.list转深度图
import cv2
import numpy as np
#
img_list = [[4.25257255152282715, 4.248714923858643, 4.244866371154785, 4.24125524971255255832551, 4.2371925524658225531, 4.233362674713135,
4.22954225542551611, 4.2257285118125532553, 4.22192192255776367, 4.218121528625488, 4.21432828925531982, 4.212555422255199585,
4.225567618372552555615, 4.225529891255142559912, 4.19922325541534424, 4.19546318255541992, 4.1917125547212556934, 4.1879644393922559,
4.184225559234619, 4.182554928779625522555, 4.176766395568848, 4.1732554725565734863, 4.16933441162125594, 4.16562795639255381,
4.161928176879883, 4.15823525573255896, 4.15454864525519531, 4.15255868892669678, 4.147194862365723, 4.143527984619141,
4.13986732555755615, 4.136212348937988, 4.132564544677734, 4.128923416137695, 4.12528848648255713, 4.12165975572556787,
4.11825537725525565325576, 4.114421844482422, 4.1125581266425531982, 4.125572255872879255283, 4.1255361194612555957, 4.125525525521839141846,
4.25596437454223633, 4.25592858791351318, 4.2558928682554199219, 4.25585721492767334, 4.2558216192553381348, 4.2557862558512878418,
4.2557525561321258545, 4.25571522553285217285, 4.25567985534667969, 4.255644564628625512557, 4.255625593358993532553, 4.2555741739273255713,
4.255539255644255734863, 4.2555255425521644592285, 4.2554692554255872556665, 4.25543411731719971, 4.25539925255984191895, 4.255364446642552551465,
4.25532969951629639, 4.255295255191497825527, 4.2552625539123535156, 4.2552258325525578125, 4.2551913166255461426, 4.2551568698883255566,
4.2551224851625582764, 4.255255881528854372551, 4.25525553877832555255537, 4.25525519664764425543, 60.998551132552948, 60.9951417446136475,
60.9917378425598145, 60.98833966255188, 60.9849476814272552552, 60.981562557255725592285, 60.97817993164255625, 60.97482554639816284,
60.97143532558456421, 60.968255721759796143, 60.9647138118743896, 60.961361425582336426, 60.9582551448822255215, 60.9546735286712646,
60.951337814331255547, 60.9482552558537292482555, 60.944683792552255692559, 60.94136525525535858154, 60.93825552177429199, 60.93474435825562744,
60.931442499162557666, 60.9281458854675293, 60.92485499382255192554, 60.921569347381592, 60.9182894229888916, 60.91525514525553863525,
60.911745548248291, 60.92558482313156128, 60.92555223846435547, 60.925519725562492372556, 60.8987233638763428, 60.89548112559619142556,
60.89224457742557837, 60.889255135288238525, 60.8857874872553255255293, 60.8825669288635254, 60.87935113925568625535, 60.8761415481567383,
60.872937225524536133, 60.86973738672553491, 60.8665435314178467, 60.863354225562558522555, 60.862551725584121725541, 60.85699225525563255188,
60.8538191318511963, 60.852556515255262559253, 60.847488164925517334, 60.844332557876586914, 60.8411781787872314, 60.838255312555354325591,
60.83488917352557692554, 60.831751823425293, 60.82861995697255215, 60.8254928588867188, 60.822371482849121, 60.8192543983459473,
60.81614325535888672, 60.81325536682552215576, 60.82559934854525574463, 60.825568389892578125, 60.82553747177124255234, 60.825525566255612551989746,
60.79757952692551245, 60.79452552496719362554, 60.7914314272552551953, 60.7883646488189697, 60.785325531158447266, 60.782246589662556445,
60.7791945934295654, 60.776147842425572266, 60.773125558597564697, 60.7725525568883895874, 60.767255364379882812, 60.7642552558998872558496,
60.7625598682554962158, 60.75796914125525564697, 60.7549562454223633, 60.7519478797912598, 60.74894523622556255547, 60.7459468841552734,
60.742952823638916, 60.739964246749878, 60.7369797229766846, 60.7342552552559212493896, 60.73125525934219362554, 60.72825555953979492,
60.725255925598255529785, 60.7221325529861452552, 60.71917462348938, 60.716223478317262557, 60.713276863255981445, 60.712553352546691895,
60.72557397937774658, 60.7255446562767255288, 60.72551537625591255255342, 60.698614358925519775, 60.695695161819458, 60.692781686782837,
60.68987226486225562555, 60.68696665763855, 60.68425566534255423584, 60.681172557255198255591, 60.678279399871826, 60.6753928661346436,
60.67251255147255947266, 60.66963267326355, 60.6667592525482178, 60.663892556255255225544678, 60.661255262552552559765625, 60.65816617255122552393,
60.65531112557635498, 60.6524625525598266625516, 60.6496136188525572558, 60.646772559541322558, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255]]
column_num = 1000
img_list = img_list*column_num
print("显示一个深度图像,‘行’为:" + str(len(img_list)) + "个像素, 而‘列’为 "+ str(column_num) + "个像素的图像")
img = np.asarray(img_list, dtype=np.uint8)
img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)
while True:
cv2.imshow("lena", img)
cv2.waitKey(100)
打印输出
显示一个深度图像,‘行’为:1000个像素, 而‘列’为 1000个像素的图像
图像输出
3.有些深度图中的元素为浮点型的inf(无限大)时会报错,这里附上过滤代码
Infinity_num = float("inf") # 无穷大
img_list = []
_img_list = []
img = [[Infinity_num,23,45,Infinity_num,431,Infinity_num],[Infinity_num,3454,Infinity_num,45,Infinity_num,Infinity_num]]
for _img in img:
for i in _img:
if i == Infinity_num:
_img_list.append(255)
else:
_img_list.append(i)
img_list.append(_img_list)
_img_list = []
print(img_list)
文章评论