Ask Your Question
1

Convert double[2048]to Mat

asked 2016-01-22 10:32:42 -0600

Guyygarty gravatar image

updated 2016-01-22 11:02:33 -0600

I have a spectrometer that receives an address and throws 2048 doubles into memory starting at that address. I would like to run it 500 times and at the end have a 500x2048 Mat file where each row corresponds to one spectrum. If the spectrometer was returning int, I would define a Mat(500,2048,CV_16UC1) and send the spectrometer the address of each row sequentially.

How do I need to define the Mat so that I can do this with doubles?

I am using windows 7/64 , Visual studio 2013 and OpenCV 2.4.9

guy

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-02-10 10:28:22 -0600

Guyygarty gravatar image

updated 2016-02-10 10:50:42 -0600

This is what I ended up using:

double Spectrum[N_SPECT][PIXEL_COUNT]; //define contiguous memory block
[...]
DLL_Get_Spectra(Spectrum[SpectrumCount], &CaseTemp);// Grab data into Spectrum[][] one row at a time
[...]
cv::Mat_<double> Image(SpectrumCount, PIXEL_COUNT, &Spectrum[0][0]);//build Mat around Spectrum[][]

It works quite well. I decided to use Mat_<double> instead of Mat(,,CV_64F) to be absolutely sure that I get the pixel type right - I was somewhat fuzzy on the exact size of a double. Why the spectrometer is returning 16 bit integers as double in the first place is beyond me.

guy

edit flag offensive delete link more
1

answered 2016-01-22 11:12:32 -0600

kbarni gravatar image

Create a row Mat for each data,then use hconcat to concatenate them in a final image. It should be something like (untested code):

Mat result;
double *data;
while(capturing){
    data=GetSpectrometerData()
    Mat datMat(1,2048,CV_64F,data);
    hconcat(result,datMat,result);
}
imshow("Captures spectra",result);
edit flag offensive delete link more

Comments

1

i think you could use vconcat(result,datMat,result); or result.push_back(datMat) instead of hconcat(result,datMat,result);

sturkmen gravatar imagesturkmen ( 2016-01-22 14:32:00 -0600 )edit

Thanks

I have a very strong aversion to memory allocation in loops. I believe in your solution I would either have to reallocate data or (implicitly) result at each cycle.

guy

Guyygarty gravatar imageGuyygarty ( 2016-02-10 10:57:56 -0600 )edit

I liked your solution

sturkmen gravatar imagesturkmen ( 2016-02-10 12:25:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-22 10:32:42 -0600

Seen: 568 times

Last updated: Feb 10 '16