当前位置:网站首页>Hisilicon AI chip (hi35xx): image JPG to BGR upgrade
Hisilicon AI chip (hi35xx): image JPG to BGR upgrade
2022-07-21 14:03:00 【FeboReigns】
https://blog.csdn.net/smf0504/article/details/106068342
I improved the code of this brother above , Small improvements , Under backup , Lest you lose
Mainly this ,self.img_size_w = 220 # save bgr size
self.img_size_h = 416 # save bgr size
The original one-dimensional data , I can distinguish the width and height here
In addition, I added test_Hi_bgr1 You can read the width and height from the file name
self.img_size_w = int(dir.split("-")[1])
self.img_size_h = int(dir.split("-")[2])
Is a simple string processing , If you want to use , Change it according to your file name , My file format is
XX-100-200.bgr, And my path E:/GraduateE_Competition/data/fu There is no ‘’ - ‘’ Of , All can put 100 200 Take it out
import cv2
class JPG2BGR_Solver(object):
def __init__(self):
self.img_size_w = 220 # save bgr size
self.img_size_h = 416 # save bgr size
# jpj2bgr converbgr=true Parameter setting
self.imgpath_jpg = r"E:\\GraduateE_Competition\\jpg2bgr\\dog4.jpg"
self.saveimg_bgr = r"E:\\GraduateE_Competition\\jpg2bgr\\dog4.bgr"
# testbgr converbgr=false Parameter setting
self.jpeg_path = r"E:\\GraduateE-Competition\\jpg2bgr\\HumanWithDog.jpg" # Just to get the height and width of the picture
#self.path = "E:\\GraduateE-Competition\\jpg2bgr\\HumanWithDog_transferred.bgr"
self.path = "E:\\GraduateE-Competition\\didi\\crop-65-308-304089172.bgr"
#self.path = "E:\\GraduateE-Competition\\jpg2bgr\\cropped\\dog_bike_car_416x416.bgr"
""" Hayes nnie The model needs input bgr Format picture , This python Script can put jpg Format of the picture into .bgr Format picture """
def jpg2bgr(self):
save_img_size_h = self.img_size_h
save_img_size_w = self.img_size_w
imgpath_jpg = self.imgpath_jpg
img = cv2.imread(imgpath_jpg)
if img is None:
print("img is none")
else:
img = cv2.resize(img, (save_img_size_w, save_img_size_h))
(B, G, R) = cv2.split(img)
with open(self.saveimg_bgr, 'wb') as fp:
for i in range(save_img_size_h):
for j in range(save_img_size_w):
fp.write(B[i, j])
# print(B[i, j])
for i in range(save_img_size_h):
for j in range(save_img_size_w):
fp.write(G[i, j])
for i in range(save_img_size_h):
for j in range(save_img_size_w):
fp.write(R[i, j])
print("save success")
""" see bgr The contents of the file are displayed as pictures """
def test_Hi_bgr(self):
jpeg_path = self.jpeg_path
path = self.path
imgsize_h = self.img_size_h
imgsize_w = self.img_size_w
f = open(path, 'rb')
src = cv2.imread(jpeg_path)
src = cv2.resize(src, (imgsize_w, imgsize_h))
print(src.shape)
h = src.shape[0]
w = src.shape[1]
c = src.shape[2]
print(f.name)
(B, G, R) = cv2.split(src)
data = f.read(imgsize_h * imgsize_w * 3)
for j in range(imgsize_h):
for i in range(imgsize_w):
B[j, i] = data[j * imgsize_w + i]
G[j, i] = data[j * imgsize_w + i + imgsize_w * imgsize_h]
R[j, i] = data[j * imgsize_w + i + imgsize_w * imgsize_h * 2]
newimg = cv2.merge([B, G, R])
cv2.imshow("new", newimg)
f.close()
cv2.waitKey(0)
def test_Hi_bgr1(self,dir):
self.path = dir
jpeg_path = self.jpeg_path
path = self.path
self.img_size_w = int(dir.split("-")[1]) # save bgr size
self.img_size_h = int(dir.split("-")[2]) # save bgr size
imgsize_h = self.img_size_h
imgsize_w = self.img_size_w
f = open(path, 'rb')
src = cv2.imread(jpeg_path)
src = cv2.resize(src, (imgsize_w, imgsize_h))
print(src.shape)
h = src.shape[0]
w = src.shape[1]
c = src.shape[2]
print(f.name)
(B, G, R) = cv2.split(src)
data = f.read(imgsize_h * imgsize_w * 3)
for j in range(imgsize_h):
for i in range(imgsize_w):
B[j, i] = data[j * imgsize_w + i]
G[j, i] = data[j * imgsize_w + i + imgsize_w * imgsize_h]
R[j, i] = data[j * imgsize_w + i + imgsize_w * imgsize_h * 2]
newimg = cv2.merge([B, G, R])
# cv2.imshow("new", newimg)
cv2.imwrite(dir+".jpg", newimg)
f.close()
# cv2.waitKey(0)
if __name__ == '__main__':
path_name='E:/GraduateE_Competition/data/fu'
import os
i = 0
for item in os.listdir(path_name):
converbgr = False
solverObj = JPG2BGR_Solver()
if (converbgr == True):
solverObj.jpg2bgr()
else:
solverObj.test_Hi_bgr1(path_name+"/"+item)
print("batch rename finished\n")
边栏推荐
- 分组查询以及筛选的区别
- 同花顺上开户安全吗,靠谱吗?
- The past, present and future of JVM
- IReport导出PDF字体加粗失效
- 【JZOF】04二维数组中的查找
- 一元多项式的乘法与加法运算
- 5款经典代码阅读器的使用方案对比
- MySQL---three 多表查询与事务的操作
- How can we make enterprise knowledge management play its real value?
- Easygbs platform setup tips: how to hide the platform web page from being accessed?
猜你喜欢
Ireport export PDF font bold failure
The relationship between cloud computing and digital transformation has finally been clarified
设置Shell脚本开机自启
主流浏览器版本检测
How can technologists start their personal brand? Exclusive teaching of top five KOLs
ES6基本了解
Penetration testing XML injection and xxE vulnerability
白宫正设法推动填补美国数十万个网络安全工作岗位
正则表达式
渗透测试-命令执行注入
随机推荐
rust反向遍历rev()
DQL语句_查询表中指定的字段_以及指定的别名_以及字段去重
浙江的哪个银行网点可以买到ETF基金产品?
Easygbs platform setup tips: how to hide the platform web page from being accessed?
DQL statement_ Fields specified in the query table_ And the specified alias_ And field de duplication
ERROR 2003 (HY000): Can‘t connect to MySQL server on ‘localhost:3306‘ (10061)
C#中缓存的使用
哎,系统分析师下午没过
Mysql数据库查询好慢,除了索引,还能因为什么?
实用技巧!!
Basic understanding of ES6
LeetCode刷题--点滴记录018
Contents to be included in the feasibility study report
IO流概述
【WMCA】《Biometric Face Presentation Attack Detection with Multi-Channel Convolutional Neural Network》
【JZOF】05替换空格
架构训练营模块七作业
_排序查询
测试/开发程序员怎样渡过中年危机?一眼就看到底了......
EasyNVS定制项目中的播放器更新及相应新功能增加