Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

InstallCallback

Hi,

I have some query on InstallCallback function(C Programming function) for the NI-IMAQ 1394 v2.0. Just want to ensure my understanding is correct and at the same time gain some insights into the grabbing process. I have written the following code:

In main code:
imaq1394InstallCallback(Sid, IMG1394_EVENT_FRAME_DONE, (IMAQ1394_CALL_BACK_PTR)GrabCallback, NULL);
imaq1394ConfigureAcquisition(Sid, TRUE ,10, rectangle);
imaq1394StartAcquisition (Sid);

In the function GrabCallback

uInt32 NI_FUNCC GrabCallback(SESSION_ID Sid, uInt32 event, int error, uInt32 cumulBufferIndex, void* userdata){
............

imaq1394GetBuffer2(Sid, IMG1394_LASTBUFFER, &bufferNumber, IMG1394_ONOVERWRITE_FAIL,(void **)&ImaqBuffer)

}

Here are my query:
1) The function GrabCallback will be called each time when a frame is completed right?
2) The setting of the buffer in ComfigureAcquisition is device buffer right? So is the writing of frames to this buffer is in the order of 0,1,2...9 then 0,1,2...9 again as long as the Grabbing process is ongoing?
3) Regarding about the IMG_LASTBUFFER attributes, should it be the previous buffer instead of next buffer as stated in the manual? I assume the buffer they are talking about is the device buffer and ImaqBuffer is the buffer to hold the acquired buffer in the camera
4) Just a query on synchronisation, is the calling of GrabCallback is in parallel with the grabbing acquisition? ie the two process GRabCallback and camera grabbing is ongoing concurrently?

Thanks for your help!
0 Kudos
Message 1 of 9
(4,578 Views)
Hello Water,

Thank you for using our discussion forums. To answer your questions:

1. Yes, GrabCallback will be called every time a buffer is acquired and transferred into system memory.
2. Your understanding of the buffers is right. The system in this case will allocate and use the buffers specified in the imaq1394ConfigureAcquisition function and the buffers will be filled from 0-9 and then repeat in the same manner.
3. The constant name for IMG1394_LASTBUFFER is a little counter intuitive, it gets the next buffer acquired, IMG1394_IMMEDIATEBUFFER to get the current buffer.
4. Yes, the two processes run in parallel.

I hope this helps.

Regards,
Nipun M
0 Kudos
Message 2 of 9
(4,567 Views)
Just some more query on the 4th part.

I am trying to use grab to collect a certain number of frames for processing. THe if condition is written in the Callback Thread. The else condition would stop the looping.

uInt32 NI_FUNCC GrabCallback(SESSION_ID Sid, uInt32 event, int error, uInt32 cumulBufferIndex, void* userdata){
............

if( num_frames < 60 ){
imaq1394GetBuffer2(Sid, IMG1394_LASTBUFFER, &bufferNumber, IMG1394_ONOVERWRITE_FAIL,(void **)&ImaqBuffer);

} else {

imaq1394StopAcqusition(Sid);
}


In the debug mode, everything seems to be working fine. I have acquired the number of frames i need. However in the real running of the program, the number of frames that are acquired are lesser than required. The situation does not improved even after I have configured to take in more buffer in imaq1394ConfigureAcquisition. I just wonder what might be the cause for this problem? Or have I used the Callback thread correctly or rather have I used it in the right form of intended usage?

Thanks for the help!
0 Kudos
Message 3 of 9
(4,565 Views)
Hello Walter,

I see that you are basing your results of when to stop the acquisition on "num_frames" how are you incrementing this variable. Is it being incremented by 1 every time the callback is executed? If you are only trying to acquire a certain number of frames and then stop, this procedure is called a sequence. I would recommend looking at the "Low Level Sequence1394" MSVC example included with NI-IMAQ. You can find all the shipping Visual C example at the following location on your drive: "..\National Instruments\NI-IMAQ for IEEE-1394\Examples\MSVC". I hope this helps. Let me know if you have other questions.

Regards,
Nipun M
0 Kudos
Message 4 of 9
(4,541 Views)
Actually I would need to project some form of pattern onto a sample and then capture the overlayered image. I have raised a query some days ago on the best ways to do this. Snapping is out as I have tried it and it is rather slow. I would think I would need to do the image acquisition and pattern projection concurrently. I was recommended to try grab function though I wonder if there is much difference between grab and sequence if applied for this case.

Would there be any difference? Thanks for your patience and help!
0 Kudos
Message 5 of 9
(4,540 Views)
Hello,

You are correct in saying that snap is slower than performing a grab. A sequence and a grab will be very similar. The reason I recommended looking at the sequence example is because it shows how to stop after certain number of buffers have been acquired. Let me know if you have other questions.

Regards,
Nipun
0 Kudos
Message 6 of 9
(4,513 Views)
Just another query. If I have used the installcallback for the sequence style of imaging, would the image acquisition process be in concurrent with the installcallback function or would the image acquisition only reproceeds after the installcallback function return the control, behaving in sequential manner?

BTW, so what exactly differentiates the two imaging mode wben the sequence is listed as non continuous acquisition while grab is listed as continuous? It seems they are rather similar although sequence mode only takes in the frames number specified by the buffer number set by user

Thanks for your help!
0 Kudos
Message 7 of 9
(4,501 Views)
At the Low level the sequence and grab are the same except for the condition to stop the process. The only difference being, sequence stops when the specified number of buffers have been acquired and grab has no such limit. If explicitly used the sequence will only return after all the buffers in the list have been acquired. I suggested using a sequence because the only function you mentioned in the grab callback was a check to see how many frames had been acquired and stopping after 60 frames, that's exactly what sequence would do. Let me know if I can help out with anything else.

Thanks,
Nipun
0 Kudos
Message 8 of 9
(4,478 Views)
Thanks for your help! It has certainly clear some of the doubts.

Some more extra queries
1) Since installcallback launches after a frame is done and runs concurrently with the acquisition still running behind the scene, there would be multiple installcallback thread that could be running right?
2) For the

imaq1394GetBuffer2 (SESSION_ID sessionID, unsigned long bufferNumberDesired, unsigned long *bufferNumberActual, unsigned long onOverwrite, void **buffer);

what does the bufferNumberActual parameter actually serves?

3) Can we actually specify the which buffer we would like to get using imaq1394GetBuffer2() assuming that we have set the buffernumber in configureAcqusition to be more than one?
0 Kudos
Message 9 of 9
(4,465 Views)