- CVI 정보나눔(www.cvi.kr)
- 스터디
- 질문답변
질문,답변
글 수 1,629
항상건강하고 행복하세요...
Framegrabber을 이용해서 영상을 캡쳐하려고합니다.
Snap를 이용해서 버퍼에 영상을 저장하고 그리고 나서 imagPlot를 이용해서
다음과같이 출력하고있습니다.
static void* ImaqBuffer=NULL;
int CVICALLBACK Snap (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int acqWinWidth, acqWinHeight;
unsigned int bufSize, bytesPerPixel, plotFlag, bitDepth;
char intfName[64];
switch (event)
{
case EVENT_COMMIT:
// Get the interface name
GetCtrlVal (panelHandle, PANEL_INTFNAME, intfName);
GetCtrlVal (panelHandle, PANEL_INTFNAME_2, intfName_2);
// Open an interface and a session
imgInterfaceOpen (intfName, &Iid);
imgSessionOpen (Iid, &Sid);
// Check that the Acquisition window is not smaller than the Canvas
imgGetAttribute (Sid, IMG_ATTR_ROI_WIDTH, &acqWinWidth);
imgGetAttribute (Sid, IMG_ATTR_ROI_HEIGHT, &acqWinHeight);
imgGetAttribute (Sid, IMG_ATTR_BYTESPERPIXEL, &bytesPerPixel);
imgGetAttribute (Sid, IMG_ATTR_BITSPERPIXEL, &bitDepth);
if(CanvasWidth < acqWinWidth)
acqWinWidth = CanvasWidth;
if(CanvasHeight < acqWinHeight)
acqWinHeight = CanvasHeight;
// Set the ROI to the size of the Canvas so that it will fit nicely
imgSetAttribute (Sid, IMG_ATTR_ROI_WIDTH, acqWinWidth);
imgSetAttribute (Sid, IMG_ATTR_ROI_HEIGHT, acqWinHeight);
imgSetAttribute (Sid, IMG_ATTR_ROWPIXELS, acqWinWidth);
// create a buffer list with one element
imgCreateBufList(1, &Bid);
// compute the size of the required buffer
bufSize = acqWinWidth * acqWinHeight * bytesPerPixel;
// create a buffer and configure the buffer list
imgCreateBuffer(Sid, FALSE, bufSize, &ImaqBuffer);
/* the following configuration assigns the following to buffer list
element 0:
1) buffer pointer that will contain the image
2) size of the buffer for buffer element 0
3) command to stop acquisition when this element is reached
*/
imgSetBufferElement(Bid, 0, IMG_BUFF_ADDRESS, (uInt32)ImaqBuffer);
imgSetBufferElement(Bid, 0, IMG_BUFF_SIZE, bufSize);
imgSetBufferElement(Bid, 0, IMG_BUFF_COMMAND, IMG_CMD_STOP);
// lock down the buffers contained in the buffer list
imgMemLock(Bid);
// configure the session to use this buffer list
imgSessionConfigure(Sid, Bid);
// start the acquisition (synchronous function)
imgSessionAcquire(Sid, TRUE, NULL);
// Display using NI-IMAQ
// set the plot Flag depending on the bitDepth
switch(bitDepth)
{
case 10:
plotFlag = IMGPLOT_MONO_10;
break;
case 12:
plotFlag = IMGPLOT_MONO_12;
break;
case 14:
plotFlag = IMGPLOT_MONO_14;
break;
case 16:
plotFlag = IMGPLOT_MONO_16;
break;
case 24:
case 32:
plotFlag = IMGPLOT_COLOR_RGB32;
break;
default:
plotFlag = IMGPLOT_MONO_8;
break;
}
imgPlot (CVIWndHndl, ImaqBuffer, 0, 0, acqWinWidth, acqWinHeight,
CanvasLeft, CanvasTop, plotFlag);
// unlock the buffers in the buffer list
if (Bid != 0)
imgMemUnlock(Bid);
// dispose the buffer
if (ImaqBuffer != NULL)
imgDisposeBuffer(ImaqBuffer);
// close this buffer list
if (Bid != 0)
imgDisposeBufList(Bid, FALSE);
// Close the interface and the session
imgClose (Sid, TRUE);
imgClose (Iid, TRUE);
break;
}
return 0;
}
현재 이미지는 288 * 576 입니다.
그런데 이상태에서 이미지를 90도 회전(576 * 288)하거나 반전해서 출력할수는 없는지요?
이미지 버퍼를 건드릴수있는지 궁금합니다. 아니면 imgPlot함수에 그런기능이있거나 또는 이미지를 회전할수있는 함수가있는지 궁금합니다.
또는 이미지를 회전해서 출력할수있는방법을 알려주세요 부탁드리겠습니다.
Framegrabber을 이용해서 영상을 캡쳐하려고합니다.
Snap를 이용해서 버퍼에 영상을 저장하고 그리고 나서 imagPlot를 이용해서
다음과같이 출력하고있습니다.
static void* ImaqBuffer=NULL;
int CVICALLBACK Snap (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int acqWinWidth, acqWinHeight;
unsigned int bufSize, bytesPerPixel, plotFlag, bitDepth;
char intfName[64];
switch (event)
{
case EVENT_COMMIT:
// Get the interface name
GetCtrlVal (panelHandle, PANEL_INTFNAME, intfName);
GetCtrlVal (panelHandle, PANEL_INTFNAME_2, intfName_2);
// Open an interface and a session
imgInterfaceOpen (intfName, &Iid);
imgSessionOpen (Iid, &Sid);
// Check that the Acquisition window is not smaller than the Canvas
imgGetAttribute (Sid, IMG_ATTR_ROI_WIDTH, &acqWinWidth);
imgGetAttribute (Sid, IMG_ATTR_ROI_HEIGHT, &acqWinHeight);
imgGetAttribute (Sid, IMG_ATTR_BYTESPERPIXEL, &bytesPerPixel);
imgGetAttribute (Sid, IMG_ATTR_BITSPERPIXEL, &bitDepth);
if(CanvasWidth < acqWinWidth)
acqWinWidth = CanvasWidth;
if(CanvasHeight < acqWinHeight)
acqWinHeight = CanvasHeight;
// Set the ROI to the size of the Canvas so that it will fit nicely
imgSetAttribute (Sid, IMG_ATTR_ROI_WIDTH, acqWinWidth);
imgSetAttribute (Sid, IMG_ATTR_ROI_HEIGHT, acqWinHeight);
imgSetAttribute (Sid, IMG_ATTR_ROWPIXELS, acqWinWidth);
// create a buffer list with one element
imgCreateBufList(1, &Bid);
// compute the size of the required buffer
bufSize = acqWinWidth * acqWinHeight * bytesPerPixel;
// create a buffer and configure the buffer list
imgCreateBuffer(Sid, FALSE, bufSize, &ImaqBuffer);
/* the following configuration assigns the following to buffer list
element 0:
1) buffer pointer that will contain the image
2) size of the buffer for buffer element 0
3) command to stop acquisition when this element is reached
*/
imgSetBufferElement(Bid, 0, IMG_BUFF_ADDRESS, (uInt32)ImaqBuffer);
imgSetBufferElement(Bid, 0, IMG_BUFF_SIZE, bufSize);
imgSetBufferElement(Bid, 0, IMG_BUFF_COMMAND, IMG_CMD_STOP);
// lock down the buffers contained in the buffer list
imgMemLock(Bid);
// configure the session to use this buffer list
imgSessionConfigure(Sid, Bid);
// start the acquisition (synchronous function)
imgSessionAcquire(Sid, TRUE, NULL);
// Display using NI-IMAQ
// set the plot Flag depending on the bitDepth
switch(bitDepth)
{
case 10:
plotFlag = IMGPLOT_MONO_10;
break;
case 12:
plotFlag = IMGPLOT_MONO_12;
break;
case 14:
plotFlag = IMGPLOT_MONO_14;
break;
case 16:
plotFlag = IMGPLOT_MONO_16;
break;
case 24:
case 32:
plotFlag = IMGPLOT_COLOR_RGB32;
break;
default:
plotFlag = IMGPLOT_MONO_8;
break;
}
imgPlot (CVIWndHndl, ImaqBuffer, 0, 0, acqWinWidth, acqWinHeight,
CanvasLeft, CanvasTop, plotFlag);
// unlock the buffers in the buffer list
if (Bid != 0)
imgMemUnlock(Bid);
// dispose the buffer
if (ImaqBuffer != NULL)
imgDisposeBuffer(ImaqBuffer);
// close this buffer list
if (Bid != 0)
imgDisposeBufList(Bid, FALSE);
// Close the interface and the session
imgClose (Sid, TRUE);
imgClose (Iid, TRUE);
break;
}
return 0;
}
현재 이미지는 288 * 576 입니다.
그런데 이상태에서 이미지를 90도 회전(576 * 288)하거나 반전해서 출력할수는 없는지요?
이미지 버퍼를 건드릴수있는지 궁금합니다. 아니면 imgPlot함수에 그런기능이있거나 또는 이미지를 회전할수있는 함수가있는지 궁금합니다.
또는 이미지를 회전해서 출력할수있는방법을 알려주세요 부탁드리겠습니다.
그런데 비젼을 달고 보니 작업자와 로봇이 상하, 좌우가
반대로 되어 있더군요.
그래서 저는 상하와 좌우를 완전히 대칭하도록 만들었습니다.
가장 고전적인 방법으로요.
//// 화면 좌우 대칭하도록 함
for(i=0;i<480;i++)
{
for(j=0;j<640;j++)
CopyBuffer1[i*640+j] = buf_temp[i*640+640-j-1];
}
//// 화면 상하 대칭하도록 함
for(i=0;i<480;i++)
{
for(j=0;j<640;j++)
CopyBuffer[i*640+j] = CopyBuffer1[(480-i-1)*640+j];
}
// Display it using imgPlot
imgPlot ((GUIHNDL)CVIWndHndl, CopyBuffer, 0, 0, AcqWinWidth, AcqWinHeight,
CanvasLeft, CanvasTop, PlotFlag);
이렇게 하니 비젼을 촬영할때 좌우와 상하가 뒤집어져 영상이 나옵니다.
이 방법으로 90도 회전도 방법을 찾으시는 것이 어떨까요?