PDA

View Full Version : problem in using two camera..



abdul_khathar
October 19, 2007, 12:14:21
hi !

i have created 1 dialog based application and linked two cameras, its working but its taking huger time and my systems is gettting slow.... :o

here is my coding

class CCam1_Listener: public GrabberListener
{
public:
virtual void frameReady( Grabber& caller, smart_ptr<DShowLib::MemBuffer> pBuffer, DWORD FrameNumber );
};

class CCam2_Listener: public GrabberListener
{
public:
virtual void frameReady( Grabber& caller, smart_ptr<DShowLib::MemBuffer> pBuffer, DWORD FrameNumber );
};

void CCam1_Listener::frameReady( Grabber& caller, smart_ptr<MemBuffer> pBuffer, DWORD currFrame)
{
int t_Y,t_X,t_padd=0,t_rv,t_gv,t_bv, t_width,t_height;
t_width = IMAGE_WIDTH;
t_height = IMAGE_HEIGHT;
BYTE *p;
p = pBuffer->getPtr();
if(Image.start_flag==1)
{

for(t_Y=0; t_Y<t_height; t_Y++) // Converting From Buffer into Array
{
for(t_X=0; t_X<t_width; t_X++)
{
t_bv = p[t_padd];
t_padd++;
t_gv = p[t_padd];
t_padd++;
t_rv = p[t_padd];
t_padd++;
t_padd++;

*(*(Image.p_pic_Array1+t_Y) + t_X) = RGB(t_bv,t_gv,t_rv);
*(*(Image.p_Master_Array+t_Y) + t_X) = RGB(t_bv,t_gv,t_rv);
}
}
Image.start_flag=0;
}


if(Image.Save_flag==1) // To Save the Image
{
t_padd=0;
for(t_Y=0; t_Y<t_height; t_Y++)
{
for(t_X=0; t_X<t_width; t_X++)
{
//Image Array 1
/* p[t_padd] = GetBValue(Image.p_pic_Array1[t_Y][t_X]);
t_padd++;
p[t_padd] = GetGValue(Image.p_pic_Array1[t_Y][t_X]);
t_padd++;
p[t_padd] = GetRValue(Image.p_pic_Array1[t_Y][t_X]);

*///

//Image Array 2
p[t_padd] = GetBValue(Image.p_pic_Array2[t_Y][t_X]);
t_padd++;
p[t_padd] = GetGValue(Image.p_pic_Array2[t_Y][t_X]);
t_padd++;
p[t_padd] = GetRValue(Image.p_pic_Array2[t_Y][t_X]);
t_padd++;
p[t_padd] = 0;
t_padd++;
}
}

CString t_path,t_filepath, cnt, t_comp_code;
char t_filename[MAX_PATH];
t_padd=0;
t_path=AfxGetApp()->m_pszHelpFilePath;

for(int t_i=1;t_i<=t_path.GetLength();t_i++)
{
if(t_path.Mid(t_i,18)=="VTS_VC_0003_070605")
{
t_path = t_path.Mid(0,t_i+18);
break;
}
}
img_count++;
// cnt.Format("%d - %d",vis.m_transaction_no, vis.m_ins);
cnt.Format("%d",img_count);
t_comp_code.Format("%d", vis.db_comp_code);
t_filepath = t_path + "\\Defective_Images\\" + t_comp_code + "\\" + cnt +".jpg";
sprintf(t_filename, "%s",t_filepath, 1);
saveToFileJPEG(*(pBuffer), t_filename);
Image.Save_flag=0;

}
}

void CCam2_Listener::frameReady( Grabber& caller, smart_ptr<MemBuffer> pBuffer, DWORD currFrame)
{
int t_Y,t_X,t_padd=0,t_rv,t_gv,t_bv, t_width,t_height;
t_width = IMAGE_WIDTH;
t_height = IMAGE_HEIGHT;
BYTE *p;
p = pBuffer->getPtr();
if(Image.start_flag==1)
{

for(t_Y=0; t_Y<t_height; t_Y++) // Converting From Buffer into Array
{
for(t_X=0; t_X<t_width; t_X++)
{
t_bv = p[t_padd];
t_padd++;
t_gv = p[t_padd];
t_padd++;
t_rv = p[t_padd];
t_padd++;
t_padd++;

*(*(Image.p_Cam2_pic_Array1+t_Y) + t_X) = RGB(t_bv,t_gv,t_rv);
*(*(Image.p_Cam2_Master_Array+t_Y) + t_X) = RGB(t_bv,t_gv,t_rv);
}
}
Image.start_flag=0;
}


if(Image.Save_flag==1) // To Save the Image
{
t_padd=0;
for(t_Y=0; t_Y<t_height; t_Y++)
{
for(t_X=0; t_X<t_width; t_X++)
{
//Image Array 1
/* p[t_padd] = GetBValue(Image.p_Cam2_pic_Array1[t_Y][t_X]);
t_padd++;
p[t_padd] = GetGValue(Image.p_Cam2_pic_Array1[t_Y][t_X]);
t_padd++;
p[t_padd] = GetRValue(Image.p_Cam2_pic_Array1[t_Y][t_X]);

*///

//Image Array 2
p[t_padd] = GetBValue(Image.p_Cam2_pic_Array2[t_Y][t_X]);
t_padd++;
p[t_padd] = GetGValue(Image.p_Cam2_pic_Array2[t_Y][t_X]);
t_padd++;
p[t_padd] = GetRValue(Image.p_Cam2_pic_Array2[t_Y][t_X]);
t_padd++;
p[t_padd] = 0;
t_padd++;
}
}

CString t_path,t_filepath, cnt, t_comp_code;
char t_filename[MAX_PATH];
t_padd=0;
t_path=AfxGetApp()->m_pszHelpFilePath;

for(int t_i=1;t_i<=t_path.GetLength();t_i++)
{
if(t_path.Mid(t_i,18)=="VTS_VC_0003_070605")
{
t_path = t_path.Mid(0,t_i+18);
break;
}
}
img_count++;
// cnt.Format("%d - %d",vis.m_transaction_no, vis.m_ins);
cnt.Format("%d",img_count);
t_comp_code = "6204" ;//.Format("%d", vis.db_comp_code);
t_filepath = t_path + "\\Defective_Images\\" + t_comp_code + "\\" + cnt +".jpg";
sprintf(t_filename, "%s",t_filepath, 1);
saveToFileJPEG(*(pBuffer), t_filename);
AfxMessageBox("Saved...");

Image.Save_flag=0;

}
}

these coding is to take a image from two cameras. it getting very slow. i have fixed 15FPS only..

please let me know or send me any sample program which is used to handle two cameras simultaneously..

thanks in advance

Abdul

Stefan Geissler
October 19, 2007, 12:54:07
Hi,

Seems you use the Classlibrary. Its the wrong forum here.


What cameras do you use?

If the image processing called in the frameReady() method takes too much time, then the grabber object will skip incoming frames until the frameReady() returns. Thus you get 15 fps only. May be you should try to optimize your image processing.

Also it would be a good idea to measure the time your image processing needs in order to check whether it lasts to long.

abdul_khathar
November 6, 2007, 06:54:08
dear stefan!

thanks for ur valuable reply..

im using DFK 21F04 cameras.

i also need to know that, can we use two activeX controls in dialogbased application(VC++6.0) to access more than one camera?

if i link that activex controls in my application, my project is getting dead slow..:( (i have linked that controls thro Wizard) why?

pls send me on sample program in which we can link two cameras and capture the images, i dont want to save that image into any file i need to process that image from buffer?

pls reply me soon

thanks in advance

Abdul Khathar

Stefan Geissler
November 6, 2007, 15:04:01
Hi Abdul,

Thank you for your answer. Using the ActiveX in a C++ program is not as good.

Before I can create a sample for you, I would like to know some more details about your image processing, especially what it should do.

The most expensive operations in your code are the copy functions and the array access ([]) operations. You should try to avoid them by accessing the images only be the BYTE* pointer returned by getPtr().
Also it seems that you use RGB32 as sink color format. You may use RGB24 only, that would save one "t_padd++;" call. But this is only marginal.

abdul_khathar
November 7, 2007, 05:19:01
hi Stefan,

good morning and thanks for ur valuable reply..

in my project im doing the following things...

1. to copy the image from image buffer and store it into double dimension array.

2. and to perform some basic image processing like thresholding and edge detection etc.,

for this i dont need to save the image. i just process it and get some results and destroy that array.

this cycle has to be done less than a second...

so u please send me 1 sample program which contains the above operation.
that will be more helpfull for me

thanks


AK