当前位置:网站首页>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 图像。
边栏推荐
- 自定dialog 布局没有居中解决方案
- The latest MySql installation teaching, very detailed
- Several forms of Attribute Changer
- MySQL高级SQL语句(二)
- cocos2d-x 实现跨平台的目录遍历
- Flutter mixed development module dependencies
- mysql password modification method in Linux (pro-test available)
- function in js
- Getting to know regular expressions
- VS通过ODBC连接MYSQL(一)
猜你喜欢
![[Cloud native] Ribbon is no longer used at the bottom layer of OpenFeign starting from the 2020.0.X version](/img/7e/1d27e3f1856ab8c6cbfc5221c717bb.png)
[Cloud native] Ribbon is no longer used at the bottom layer of OpenFeign starting from the 2020.0.X version

softmax函数详解

场效应管 | N-mos内部结构详解

How MySQL - depots table?A look at will understand

Common JVM interview questions and answers

Gradle sync failed: Uninitialized object exists on backward branch 142

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

Nmap的下载与安装

为数学而歌之伯努利家族

Access database query
随机推荐
微信小程序源码获取与反编译方式
著名网站msdn.itellyou.cn原理分析
朴素贝叶斯文本分类(代码实现)
Several solutions for mysql startup error The server quit without updating PID file
Nmap的下载与安装
unicloud 发布后小程序提示连接本地调试服务失败,请检查客户端是否和主机在同一局域网下
This in js points to the prototype object
安装Multisim出现 No software will be installed or removed解决方法
Linux modify MySQL database password
Sqlite A列数据复制到B列
js中流程控制语句
quick-3.5 lua调用c++
cocos2d-x-3.x 修改和纪录
CMOS管原理,及其在推挽电路中的应用
MySQL高级语句(一)
网页截图与反向代理
VS通过ODBC连接MYSQL(一)
powershell统计文件夹大小
Error: Cannot find module 'D:\Application\nodejs\node_modules\npm\bin\npm-cli.js'
[swagger close] The production environment closes the swagger method