This post is about how to copy Mat data to vector and copy vector data to Mat.
Reference this example source code.
printf("/////////////////////////////////////////////////////////////\n");printf("//vector to Mat\n");int r=3;int c=4;vector< float> Vf;//insert valueint cnt=0;for(int i=0; i< c; ++i)for(int j=0; j< r; ++j)Vf.push_back(cnt++);//create MatMat M=Mat(r,c,CV_32FC1);//copy vector to matmemcpy(M.data,Vf.data(),Vf.size()*sizeof(float));//print Matcout < < M < < endl;printf("/////////////////////////////////////////////////////////////\n");printf("//Mat to vector\n");vector< float> Vf2;//copy mat to vectorVf2.assign((float*)M.datastart, (float*)M.dataend);//confirmcnt=0;for(int i=0; i< c; ++i){for(int j=0; j< r; ++j)printf("%lf ", Vf2[cnt++]);printf("\n");}
--
You want to copy image buffer to Mat example source code.
Reference on this page -> http://feelmare.blogspot.kr/2014/01/opencv-mat-class-image-bufferpoint-copy.html
thanks a lot! :)
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI tryed to use this solution in my code but it crash, I tryed the same code shown above and it crash too, I think it is because the memcpy. Any idea?
ReplyDeleteDoes the length of the data was entered correctly in memcpy param 3rd?
Deleteon line 15, CV_32FC1 means 32bit float and 1 channel.
Thank you.
The data are the same that you used. I copy&paste your code.
ReplyDeleteFor people who have problems with this code to copy a vector to a mat, you can also use this:
ReplyDeletevector oOutput; // fill this with data
int iHeight = 5;
int iWidth = 4;
Mat oRealOutput;
oRealOutput = Mat(iHeight, iWidth, CV_64F);
int k = 0;
for (int i = 0; i< oRealOutput.rows; ++i)
{
for (int j = 0; j< oRealOutput.cols; ++j)
{
oRealOutput.at< double >(i, j) = oOutput[k];
k = k + 1;
}
}
Thank you for answer.
DeleteMay be, this problem is 64 and 32bit problem.
If your build option is 64bit, than you use CV_64.
otherwise your build option is 32bit, than you use like sample code.
I think that.
Thank you
The Vector doesnt have any attributes "assign"
ReplyDeleteGreat things you’ve always shared with us. Just keep writing this kind of posts.The time which was wasted in traveling for tuition now it can be used for studies.Thanks convert into vector
ReplyDeleteI appreciated your work very thanks Designers Earn 95% commission
ReplyDeleteBut a copy machine is not always cheap. photocopy machine
ReplyDeleteWe are elite in our services because we provide the best Embroidery Digitizing Services. We have introduced a variety of deals Embroidery designs and packages for our clients. Embroidery Digitizing
ReplyDeleteBitmap workmanship is related to document names finishing off with .gif, .bmp, .jpeg, .jpg, .png, and .pcx. Vector workmanship records are ordinarily spared as .eps, .ai, or .cdr documents. Vector workmanship is numerical calculations made utilizing programming programs, for example, Adobe Illustrator, Freehand, Corel Draw, Quark and a couple of others. These projects use mathematic conditions and mathematical natives (focuses, lines, and shapes) to make craftsmanship that is spotless, camera prepared, and can be scaled limitlessly, without losing any quality or lucidity. A similar workmanship might be utilized for a business card, to a banner, to a board. Professional graphic design
ReplyDelete