代码测试:unsigned char*图像数据转换成OpenCV中Mat类型

 

直接使用Mat的构造函数,把指针的位置赋给下面中的data就OK了:

Mat(int rows, int cols, int type, void* data, size_t step=AUTO_STEP);

代码为matTest.cpp

 

 

复制代码

// matTest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/features2d.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/legacy/legacy.hpp"
#include<math.h>
#include <string>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    uchar c[100][100];
    for(int i=0; i<100; i++)
    for(int j=0; j<100; j++)
        c[i][j] = (i<j)?0:255;
            imshow("x", Mat(100, 100, CV_8UC1, (void *)c));
            waitKey();
    return 0;
}

复制代码

运行结果:

 

Mat(int _rows, int _cols, int _type, void* _data, size_t _step=AUTO_STEP);    

Mat(Size _size, int _type, void* _data, size_t _step=AUTO_STEP);

 

 

opencv下char数组数据显示_百度知道 https://zhidao.baidu.com/question/304116674485151964.html

char的范围是-128~127,应该用uchar类型。构造一个数据指针指向char数组的Mat。

【ζั͡ޓއ 似爱而非、】 至此只为原地流浪.......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值