user2481422
user2481422

Reputation: 868

how to create own matrix in openCV

Hi in the following link http://www.prism.gatech.edu/~ahuaman3/docs/OpenCV_Docs/tutorials/basic_0/basic_0.html it is shown how to create a uniform matrix where all elements are 23. How can I create a matrix of

-1, -1, -1, -1, -1, -1, -1, 
 0, 0, 0, 0, 0, 0, 0, 
 2, 2, 2, 2, 2, 2, 2, 
 2, 2, 2, 2, 2, 2, 2, 
 2, 2, 2, 2, 2, 2, 2, 
 0, 0, 0, 0, 0, 0, 0, 
 -1, -1, -1, -1, -1, -1, -1, 

in openCV. I want the user to input the no. of rows of 2. How I can do that?

Upvotes: 1

Views: 3956

Answers (1)

LovaBill
LovaBill

Reputation: 5139

uchar mydata[]={1, 2, 1, 1, 2, 1, 1, 2, 1};
cv::Mat mymat(3,3,CV_8UC1,mydata);

mymat:

1 2 1
1 2 1
1 2 1

Upvotes: 4

Related Questions