Ask Your Question

Revision history [back]

If you want a dynamically growing matrix, than simply use the data structures provided for that, which is called a vector. Do this as follows.

// Initiate original value
// Using the C++11 standard
vector<int> data {255,0,255,0,0,0}; 
// Using older standards
int elements[5] = {255,0,255,0,0,0};
vector<int> data(&elements[0], &elements[0]+5);
// Now add an element --> same for both standards
data.push_back(50);

If you want a dynamically growing matrix, than simply use the data structures provided for that, which is called a vector. Do this as follows.

// Initiate original value
// Using the C++11 standard
vector<int> data {255,0,255,0,0,0}; 
// Using older standards
int elements[5] = {255,0,255,0,0,0};
vector<int> data(&elements[0], &elements[0]+5);
&elements[0]+6);
// Now add an element --> same for both standards
data.push_back(50);

EDIT: If you want to add the information in the case you supplied, you can do it maybe a bit simpler. The only thing I am wondering is why you would convert integer data to floating point type, but probably thats for further processing. Also it kind of depends how versatile you want your code to be. A simple suggestion could be.

bool bSuccess = cap.read(frame_gray, CV_LOAD_IMAGE_GRAYSCALE); //you need to specify explicitly if you want to read in grayscale!
Mat data = frame_gray.reshape(1,1);
Mat result (1, 7, CV_8UC1); //Because I am guessing that data is of this type and that you know how much elements you will add
result.at<uchar>(1,1) = data.at<uchar>(1,1);
result.at<uchar>(1,2) = data.at<uchar>(1,2);
result.at<uchar>(1,3) = data.at<uchar>(1,3);
result.at<uchar>(1,4) = data.at<uchar>(1,4);
result.at<uchar>(1,5) = data.at<uchar>(1,5);
result.at<uchar>(1,6) = data.at<uchar>(1,6);
result.at<uchar>(1,7) = 50; //Add information to the end
result.convertTo(result, CV_32F);

If you want a dynamically growing matrix, than simply use the data structures provided for that, which is called a vector. Do this as follows.

// Initiate original value
// Using the C++11 standard
vector<int> data {255,0,255,0,0,0}; 
// Using older standards
int elements[5] = {255,0,255,0,0,0};
vector<int> data(&elements[0], &elements[0]+6);
// Now add an element --> same for both standards
data.push_back(50);

EDIT: If you want to add the information in the case you supplied, you can do it maybe a bit simpler. The only thing I am wondering is why you would convert integer data to floating point type, but probably thats for further processing. Also it kind of depends how versatile you want your code to be. A simple suggestion could be.

bool bSuccess = cap.read(frame_gray, CV_LOAD_IMAGE_GRAYSCALE); //you need to specify explicitly if you want to read in grayscale!
Mat data = frame_gray.reshape(1,1);
Mat result (1, 7, CV_8UC1); //Because I am guessing that data is of this type and that you know how much elements you will add
result.at<uchar>(1,1) = data.at<uchar>(1,1);
result.at<uchar>(1,2) = data.at<uchar>(1,2);
result.at<uchar>(1,3) = data.at<uchar>(1,3);
result.at<uchar>(1,4) = data.at<uchar>(1,4);
result.at<uchar>(1,5) = data.at<uchar>(1,5);
result.at<uchar>(1,6) = data.at<uchar>(1,6);
result.at<uchar>(1,7) = 50; //Add information to the end
result.convertTo(result, CV_32F);