# 按照比例将图片切割
image = cv2.imread(fname1)
# 获取图片长宽高
sp = image.shape
sz1 = sp[0] # height(rows) of image
sz2 = sp[1] # width(colums) of imag
# 取下部分四分之一
# int((3 / 4)纵开始,sz1纵结束
# 0 横开始,sz2横结束
image = image[int((3 / 4) * sz1):sz1, 0:sz2]
# 图片显示,停留一段时间
cv2.imshow("sss", image)
cv2.waitKey(0)
-----------------------------------------------------
# 字节流与numpy之间的转换
# 图片转为字节流
import cv2
import numpy as np
img_src = cv2.imread("E:/result_data/1.jpg")
img_byte = img_src.tobytes()
# 字节流转为图片
buff_array = np.fromstring(image_stream, np.uint8)
img = cv2.imdecode(buff_array, cv2.IMREAD_COLOR)
---------------------------------------------------------
# 当图像数据为xmin, ymin, w, h = bbox时,进行切割
cname, bbox, score = dt['category'], dt['bbox'], dt['score']
# xmin, ymin, w, h = bbox
# 先纵坐标,再横坐标
if score > 0.5: # 判断置信度
image = img[int(bbox[1]):int(bbox[1] + bbox[3]), int(bbox[0]):int(bbox[0] + bbox[2])]
buff_array = image.tobytes()
print(buff_array)
cv2.imshow("sss", image)
cv2.waitKey(0)
图像知识汇总
最新推荐文章于 2024-11-02 16:28:26 发布