当前位置:网站首页>OpenCV中的图像数据格式CV_8U定义
OpenCV中的图像数据格式CV_8U定义
2022-07-31 05:15:00 【Cassiel_cx】
今天在对 16 位的深度图提取 HOG 特征时,遇到了以下问题:
代码如下:
import cv2
import numpy as np
reff_image = cv2.imread(os.path.join('C:/Users/DELL/Desktop/imgs', image_dir[j]), -1)
img_gradx = cv2.convertScaleAbs(cv2.Sobel(reff_image,cv2.CV_16S,1,0))
img_grady = cv2.convertScaleAbs(cv2.Sobel(reff_image,cv2.CV_16S,0,1))
reff_image = cv2.addWeighted(img_gradx,0.5,img_grady,0.5,0)
cell_size = (6, 6)
num_cells_per_block = (2, 2)
block_size = (num_cells_per_block[0] * cell_size[0], num_cells_per_block[1] * cell_size[1])
x_cells = reff_image.shape[1] // cell_size[0]
y_cells = reff_image.shape[0] // cell_size[1]
h_stride = 1
v_stride = 1
block_stride = (cell_size[0] * h_stride, cell_size[1] * v_stride)
num_bins = 9
win_size = (x_cells * cell_size[0] , y_cells * cell_size[1])
hog = cv2.HOGDescriptor(win_size, block_size, block_stride, cell_size, num_bins)
hog_descriptor_reff = hog.compute(reff_image)Error 如下:

问题出在读取图片的格式不对,图片的数据类型如下:
in:print(reff_image.dtype)
out:uint16显然不满足 CV_8U || CV_8UC3 的要求,将图像的数据类型改成 uint8 后,便可解决此问题。
reff_image = reff_image.astype(np.uint8)问题解决后,查阅官方文档并做如下记录:
OpenCV 中的 img.type() 格式如下:
CV_<bit_depth>(S|U|F)C<number_of_channels>
1、bit_depth:比特数,有代表 8bite\16bite\32bite\64bite;
2、S|U|F:S 表示有符号整型 (signed int),U 表示无符号整型 (unsigned int),F 表示单精度浮点型 (float);
3、<number_of_channels>:代表所存储的图片的通道数。1 为单通道图像 (灰度图),3 为 RGB 图像。
边栏推荐
猜你喜欢

VS connects to MYSQL through ODBC (1)

通信原理——纠错编码 | 汉明码(海明码)手算详解

WeChat applet source code acquisition and decompilation method

MySql创建数据表

This in js points to the prototype object

On the side of Ali, tell me what are the application scenarios of message middleware you know?

VS2017连接MYSQL

腾讯云GPU桌面服务器驱动安装

Gradle sync failed: Uninitialized object exists on backward branch 142
![[swagger close] The production environment closes the swagger method](/img/43/17be22626ba152b33beaf03f92fbec.png)
[swagger close] The production environment closes the swagger method
随机推荐
Pure shell implementation of text replacement
cocos2d-x-3.2图片灰化效果
【云原生】SQL(及存储过程)跑得太慢怎么办?
NFTs: The Heart of Digital Ownership
5 methods of MySQL paging query
flutter 混合开发 module 依赖
js中的对象与函数的理解
VTK:Could not locate vtkTextRenderer object.
qt:cannot open C:\Users\某某某\AppData\Local\Temp\main.obj.15576.16.jom for write
Filter out egrep itself when using ps | egrep
[Cloud native] Simple introduction and use of microservice Nacos
The latest MySql installation teaching, very detailed
场效应管 | N-mos内部结构详解
[Ubuntu20.04 installs MySQL and MySQL-workbench visualization tool]
MYSQL事务与锁问题处理
The server time zone value ‘й‘ is unrecognized or represents more than one time zone
VTK环境配置
cocoscreator 显示刘海内容
MySQL面试题大全(陆续更新)
C语言 | 获取字符串里逗号间隔的内容