当前位置:网站首页>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 图像。
边栏推荐
- 为数学而歌之伯努利家族
- function in js
- Several forms of Attribute Changer
- [Cloud Native] What should I do if SQL (and stored procedures) run too slowly?
- TransactionTemplate 事务编程式写法
- Filter out egrep itself when using ps | egrep
- kotlin 插件更新到1.3.21
- js中流程控制语句
- 浏览器查找js绑定或者监听的事件
- On the side of Ali, tell me what are the application scenarios of message middleware you know?
猜你喜欢

NFTs: The Heart of Digital Ownership

Why does read in bash need to cooperate with while to read the contents of /dev/stdin

What is the difference between NFT and digital collection?

最新MySql安装教学,非常详细

安装Multisim出现 No software will be installed or removed解决方法

为数学而歌之伯努利家族

VS2017连接MYSQL

【云原生】SQL(及存储过程)跑得太慢怎么办?

UiBot存在已打开的MicrosoftEdge浏览器,无法执行安装

对js的数组的理解
随机推荐
mysql common commands
ERROR Error: No module factory availabl at Object.PROJECT_CONFIG_JSON_NOT_VALID_OR_NOT_EXIST ‘Error
Sqlite column A data is copied to column B
[Elastic-Job] Overview of Distributed Scheduling Tasks
understand js operators
网页截图与反向代理
自定dialog 布局没有居中解决方案
sqlmap injection tutorial common commands
powershell统计文件夹大小
Understanding of objects and functions in js
SQLite 查询表中每天插入的数量
qt:cannot open C:\Users\某某某\AppData\Local\Temp\main.obj.15576.16.jom for write
CMOS管原理,及其在推挽电路中的应用
ERROR Error: No module factory availabl at Object.PROJECT_CONFIG_JSON_NOT_VALID_OR_NOT_EXIST ‘Error
Attribute Changer的几种形态
[Cloud native] Open source data analysis SPL easily copes with T+0
Tencent Cloud Lightweight Server deletes all firewall rules
Build DVWA with phpstudy
朴素贝叶斯文本分类(代码实现)
jenkins +miniprogram-ci 一键上传微信小程序