总是混淆的HW
python
import cv2 import numpy as np ''' opencv的image数据格式就是用numpy unit8 格式存储的。两者之间可以相互转换 ''' img = cv2.imread("../img/1.jpg") print(img.shape) # (1080, 1920, 3) HWC print(img.dtype) # dtype('uint8') img = cv2.resize(img, (640, 320), dytpe=np.uint8) # resize参数:W,H # cv2.imshow("cc", img) # cv2.waitKey() print(img.shape) # (320, 640, 3) HWC new_img = np.zeros((1080, 1920, 3), dtype=np.uint8) # HWC cv2.imshow("cc", new_img) #如果不是uint8格式,那么imshow是会自动转换 cv2.waitKey() print(new_img.shape)
c++
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main() { Mat img = imread("zidane.jpg"); //图片是1280*720 cout << sizeof(img) << endl; int rows = img.rows; //720 矩阵的行数 高 int cols = img.cols; //1280 矩阵的列数 宽 int channels = img.channels(); cout << "rows:" << rows << " cols:" << cols << "channels:"<<channels<< endl; cout << "size:" << img.size() << endl; //size:[1280 x 720] cout << "width:" << img.size().width << endl; //width:1280 cout << "height:" << img.size().height << endl; //height:720 Size dsize = Size(800, 600);//宽 高 resize(img, img, dsize, 0, 0, cv::INTER_AREA); cout << "size:" << img.size() << endl; //size:[800 x 600] // 构建Mat Mat a1(1280, 640, CV_8UC3); int rows1 = a1.rows; //1280 矩阵的行数 高 int cols1 = a1.cols; //640 矩阵的列数 宽 int channels1 = a1.channels(); cout << "rows1:" << rows1 << " cols1:" << cols1 << "channels1:" << channels1 << endl; //Rect初始化 cv::Point point1 = cv::Point(10, 10); cv::Point point2 = cv::Point(20,20); cv::Rect boxPoint = cv::Rect(point1, point2);//可以通过对角点来初始化,但Rect只有x,y,width,heigth的属性 cv::Rect box = cv::Rect(10,20,100,300); //通过x,y,width,heigth来初始化 return 0; }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探