OpenCV读取yuv420对应的灰度图像
2017-06-23 16:06
225 查看
OpenCV读取yuv420对应的灰度图像
程序代码如下:#include <OpenCV/highgui.h> #include <iostream> using namespace std; #define nWidth 448 #define nHeight 336 #define FrameSize nWidth*nHeight*3/2 int main() { FILE *f ; if(!(f = fopen("C:\\Users\\Administrator\\Desktop\\yuv_pic\\图片_448x336.yuv","rb"))) { cout << "file open error!" << endl; } // 计算帧数 fseek(f, 0, SEEK_END); int frame_count = 0; long file_size = 0; frame_count = (int) ((int)ftell(f)/((nWidth * nHeight * 3) / 2)); cout << "frame num is " << frame_count << endl; cout << "file length is " << ftell(f) << endl; fseek(f, 0, SEEK_SET); IplImage *image = cvCreateImage(cvSize(nWidth, nHeight),IPL_DEPTH_8U,1); // 控制只显示灰度图像 unsigned char *pBuf = new unsigned char[nWidth*nHeight*3/2]; fread(pBuf, 1, (nWidth * nHeight * 3) / 2, f); cvSetData(image, pBuf, nWidth); cvNamedWindow("显示"); cvShowImage("显示", image); cvWaitKey( 0 ); cvDestroyWindow("显示"); cvReleaseImage(&image); delete []pBuf; fclose(f); return 0; }
程序执行结果如下:
相关文章推荐
- 【OpenCV应用笔记】(彩色/灰度)图像像素值读取并保存到txt文件
- 一个基于opencv的显示一个rgb图像各点灰度值及对应的灰度图象灰度值的程序
- OpenCV应用笔记】(彩色/灰度)图像像素值读取并保存到txt文件
- VS2015 编译DCMTK,读取CT图像并转换为OpenCV格式
- opencv获取灰度图像直方图
- 利用MFC和opencv读取视频显示图像方法
- opencv3.3.0在线读取网络图片图像资源
- C++ OpenCV 实现RGB彩色图像转化成灰度图像再转换成二值图像
- 使用OpenCv将图像转化为灰度图像
- 用OpenCV 读取 png 中含有 alpha 的图像
- opencv学习笔记 一 图像读取与操作
- opencv从零开始——6. 图像的读取和像素遍历
- opencv读取图像像素值
- OpenCV(C++接口)学习笔记1-图像读取、显示、保存
- OpenCV 读取、修改、保存图像
- python-opencv笔记 图像的读取和简单几何图形绘制
- OpenCV读取摄像头显示原图像和RGB三通道直方图
- opencv不能成功读取图像
- OpenCV之灰度直方图反向投影(图像相似性检测)
- 在OpenCV环境下写的灰度图像二维傅里叶换,幅值计算,频谱平移和将数值归一化到0到255区间的四个函数