BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Slow scanline

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Peter Fagerbrant
Guest





PostPosted: Wed Jan 19, 2005 1:27 pm    Post subject: Slow scanline Reply with quote



I am using a USB camera with a framecapture rate of 30 fps. The camera
deliver the graphics as a jpeg image and I have to convert it to 8 bit
greyscaled bitmap and store in arrays.

I Use this for storing the bitmapinfo in a array:

for( int y=0;y<CAMRESY;y++){
xoffsIn = 0;
BYTE* pLine = (BYTE*) ((THackJPEGImage*)JPEGImage)->Bitmap->ScanLine[y];

for( int x=0;x int r = pLine[ xoffsIn + 0];
int g = pLine[ xoffsIn + 1];
int b = pLine[ xoffsIn + 2];

int iGrey = b*0.11 + g*0.59 + r*0.30;
pData8Out[ x + yoffsOut ] = iGrey;
xoffsIn += 3;
}

yoffsIn += CAMRESX+CAMRESX+CAMRESX;
yoffsOut += CAMRESX;
}

I do it in realtime. Unfortenly its impacts performens more then I want. The
camera delivers 30 fps and with this aproach I can only process 12-15 fps.
Is there a faster way to do this? I need more then 15fps. I would bee happy
with 20fps.
Anyone who has a clue?
Scanline consumes to much of the proccessingpower I need.

Best reg.
Peter Fagerbrant


Back to top
Jonathan Benedicto
Guest





PostPosted: Wed Jan 19, 2005 6:45 pm    Post subject: Re: Slow scanline Reply with quote



What is pData8Out ?

I tried to do some tweaking with your code, and by trimming out all the
xoffsIn, yOffsIn and yOffsOut and removing the pData8Out line, I was able to
achieve a simulated 83-85 fps.

To do this sim, I used a 640x480 jpeg, and used a for loop to simulate 1000
frames being processed.

But to be able to really tweak your code, I need to know how your are
storing the grey values into the pData8Out array.

--
Jonathan

"Peter Fagerbrant" <peter (AT) fagerbrant (DOT) com> wrote

Quote:
I am using a USB camera with a framecapture rate of 30 fps. The camera
deliver the graphics as a jpeg image and I have to convert it to 8 bit
greyscaled bitmap and store in arrays.

I Use this for storing the bitmapinfo in a array:

for( int y=0;y<CAMRESY;y++){
xoffsIn = 0;
BYTE* pLine = (BYTE*) ((THackJPEGImage*)JPEGImage)->Bitmap->ScanLine[y];

for( int x=0;x int r = pLine[ xoffsIn + 0];
int g = pLine[ xoffsIn + 1];
int b = pLine[ xoffsIn + 2];

int iGrey = b*0.11 + g*0.59 + r*0.30;
pData8Out[ x + yoffsOut ] = iGrey;
xoffsIn += 3;
}

yoffsIn += CAMRESX+CAMRESX+CAMRESX;
yoffsOut += CAMRESX;
}

I do it in realtime. Unfortenly its impacts performens more then I want.
The
camera delivers 30 fps and with this aproach I can only process 12-15 fps.
Is there a faster way to do this? I need more then 15fps. I would bee
happy with 20fps.
Anyone who has a clue?
Scanline consumes to much of the proccessingpower I need.

Best reg.
Peter Fagerbrant




Back to top
Peter Fagerbrant
Guest





PostPosted: Wed Jan 19, 2005 8:22 pm    Post subject: Re: Slow scanline Reply with quote



Jonathan Benedicto wrote:
Quote:
What is pData8Out ?

I tried to do some tweaking with your code, and by trimming out all the
xoffsIn, yOffsIn and yOffsOut and removing the pData8Out line, I was able to
achieve a simulated 83-85 fps.

To do this sim, I used a 640x480 jpeg, and used a for loop to simulate 1000
frames being processed.

But to be able to really tweak your code, I need to know how your are
storing the grey values into the pData8Out array.

pData8Out is just a pointer to a bigger array


struct CAPIMAGE
{
DWORD dwTime;
BYTE Data[CAMRESX*CAMRESY]; //640x480
};

pImages = new CAPIMAGE[MAXIMAGES]; //MAXIMAGES=50

BYTE* pData8Out = pImages[iIndex].Data;

I use index as the index of captured frames.


Without the for( int y=0;y<CAMRESY;y++) {...}
It runs with 26-30 fps. (Near max of the camera output)

When I comment out the for( int x=0;x but keeps y loop including BYTE* pLine = (BYTE*)
((THackJPEGImage*)JPEGImage)->Bitmap->ScanLine[y];
It drops to 15fps.

When I commenting out the "JPEGImage)->Bitmap->ScanLine[y];"
Enabling the x loop but only do:
for( int x=0;x {
int r = 11; //pLine[ xoffsIn + 0];
int g = 11; //pLine[ xoffsIn + 1];
int b = 11; //pLine[ xoffsIn + 2];

int iGrey = b*0.11 + g*0.59 + r*0.30;
pData8Out[ x + yoffsOut ] = iGrey;
xoffsIn += 3;
}
It runs on 22-26 fps

This is my testrunnings from today.

Best reg.
Peter Fagerbrant


Back to top
Peter Fagerbrant
Guest





PostPosted: Wed Jan 19, 2005 8:48 pm    Post subject: Re: Slow scanline Reply with quote

And in the callbackfunction I fill the JPEGImage with the below code
before my call to the function "storeGrayScale2Bitmap"

BYTE *MemPtr = lpVHdr->lpData;
stream->Write(MemPtr, lpVHdr->dwBytesUsed);
stream->Position = 0;
JPEGImage->LoadFromStream ( stream );

reg/
PFa

Back to top
Jonathan Benedicto
Guest





PostPosted: Wed Jan 19, 2005 11:06 pm    Post subject: Re: Slow scanline Reply with quote

I think that you might be able to do a couple things to get faster
framerate.

The first thing is maybe to get the bitmap bits into a BYTE array instead of
calling ScanLine. Eg. use something like GetDIBits or somethings like that
to directly access the data.

Then you could also globalize all of your int and BYTE declarations in that
function.

And maybe, don't use those xoffsIn, yOffsIn and yOffsOut variables, but
rather use the x and y variables. This is so that you can reduce the amount
of math the chip does.

--
Jonathan

"Peter Fagerbrant" <peter (AT) fagerbrant (DOT) com> wrote

Quote:
Jonathan Benedicto wrote:
What is pData8Out ?

I tried to do some tweaking with your code, and by trimming out all the
xoffsIn, yOffsIn and yOffsOut and removing the pData8Out line, I was able
to achieve a simulated 83-85 fps.

To do this sim, I used a 640x480 jpeg, and used a for loop to simulate
1000 frames being processed.

But to be able to really tweak your code, I need to know how your are
storing the grey values into the pData8Out array.

pData8Out is just a pointer to a bigger array

struct CAPIMAGE
{
DWORD dwTime;
BYTE Data[CAMRESX*CAMRESY]; //640x480
};

pImages = new CAPIMAGE[MAXIMAGES]; //MAXIMAGES=50

BYTE* pData8Out = pImages[iIndex].Data;

I use index as the index of captured frames.


Without the for( int y=0;y<CAMRESY;y++) {...}
It runs with 26-30 fps. (Near max of the camera output)

When I comment out the for( int x=0;x but keeps y loop including BYTE* pLine = (BYTE*)
((THackJPEGImage*)JPEGImage)->Bitmap->ScanLine[y];
It drops to 15fps.

When I commenting out the "JPEGImage)->Bitmap->ScanLine[y];"
Enabling the x loop but only do:
for( int x=0;x {
int r = 11; //pLine[ xoffsIn + 0];
int g = 11; //pLine[ xoffsIn + 1];
int b = 11; //pLine[ xoffsIn + 2];

int iGrey = b*0.11 + g*0.59 + r*0.30;
pData8Out[ x + yoffsOut ] = iGrey;
xoffsIn += 3;
}
It runs on 22-26 fps

This is my testrunnings from today.

Best reg.
Peter Fagerbrant




Back to top
KL Chin
Guest





PostPosted: Thu Jan 20, 2005 1:07 am    Post subject: Re: Slow scanline Reply with quote

Hi,

Try to use pre-calaculate result for

int iGrey = b*0.11 + g*0.59 + r*0.30;

into grgb[3][256];


iGrey = grgb[0][r] + grgb[1][g] + grgb[2][b];


Regards
KL Chin

"Peter Fagerbrant" <peter (AT) fagerbrant (DOT) com> wrote

Quote:
Jonathan Benedicto wrote:
What is pData8Out ?

I tried to do some tweaking with your code, and by trimming out all the
xoffsIn, yOffsIn and yOffsOut and removing the pData8Out line, I was able
to achieve a simulated 83-85 fps.

To do this sim, I used a 640x480 jpeg, and used a for loop to simulate
1000 frames being processed.

But to be able to really tweak your code, I need to know how your are
storing the grey values into the pData8Out array.

pData8Out is just a pointer to a bigger array

struct CAPIMAGE
{
DWORD dwTime;
BYTE Data[CAMRESX*CAMRESY]; //640x480
};

pImages = new CAPIMAGE[MAXIMAGES]; //MAXIMAGES=50

BYTE* pData8Out = pImages[iIndex].Data;

I use index as the index of captured frames.


Without the for( int y=0;y<CAMRESY;y++) {...}
It runs with 26-30 fps. (Near max of the camera output)

When I comment out the for( int x=0;x but keeps y loop including BYTE* pLine = (BYTE*)
((THackJPEGImage*)JPEGImage)->Bitmap->ScanLine[y];
It drops to 15fps.

When I commenting out the "JPEGImage)->Bitmap->ScanLine[y];"
Enabling the x loop but only do:
for( int x=0;x {
int r = 11; //pLine[ xoffsIn + 0];
int g = 11; //pLine[ xoffsIn + 1];
int b = 11; //pLine[ xoffsIn + 2];

int iGrey = b*0.11 + g*0.59 + r*0.30;
pData8Out[ x + yoffsOut ] = iGrey;
xoffsIn += 3;
}
It runs on 22-26 fps

This is my testrunnings from today.

Best reg.
Peter Fagerbrant




Back to top
Peter Fagerbrant
Guest





PostPosted: Thu Jan 20, 2005 9:08 am    Post subject: Re: Slow scanline Reply with quote


"KL Chin" <klchin (AT) 1asia (DOT) com.my> skrev i meddelandet
news:41ef0469 (AT) newsgroups (DOT) borland.com...
Quote:
Hi,

Try to use pre-calaculate result for

int iGrey = b*0.11 + g*0.59 + r*0.30;

into grgb[3][256];


iGrey = grgb[0][r] + grgb[1][g] + grgb[2][b];


The LUT gives me about one fps extra in speed.

Its a bit on the right way
Thanks.

reg/
PFa



Back to top
Peter Fagerbrant
Guest





PostPosted: Thu Jan 20, 2005 9:13 am    Post subject: Re: Slow scanline Reply with quote


"Jonathan Benedicto" <incorrect (AT) no (DOT) server> skrev i meddelandet
news:41eee7f7$1 (AT) newsgroups (DOT) borland.com...
Quote:
I think that you might be able to do a couple things to get faster
framerate.

The first thing is maybe to get the bitmap bits into a BYTE array instead
of calling ScanLine. Eg. use something like GetDIBits or somethings like
that to directly access the data.

I cleaning the mathroutine.

I't sounds like GetDIBits is a solution. From what I seen in this
discussions, the scanline recreates the bitmap for every call. Its a waste
in my case. If I could have the bitmaparray in one pice and traverse it,
naturily it would be much faster.
I'l dig a bit about how to use the GetDIBits in my case.

Reg/
PFa



Back to top
Hans Galema
Guest





PostPosted: Thu Jan 20, 2005 10:02 am    Post subject: Re: Slow scanline Reply with quote

Jonathan Benedicto wrote:

Quote:
And maybe, don't use those xoffsIn, yOffsIn and yOffsOut variables, but
rather use the x and y variables. This is so that you can reduce the amount
of math the chip does.

You mean something like:

for( int y=0;y<CAMRESY;y++){
BYTE* pLine = (BYTE*) ((THackJPEGImage*)JPEGImage)->Bitmap->ScanLine[y];

for( int x=0;x int r = *pLine++;
int g = *pLine++;
int b = *pLine++;

int iGrey = .....

pData8Out[ x + yoffsOut ] = iGrey;
}
}

One could use a pointer for pDat8Out too.

Please trim quotes. You even triple them.

Hans.

Back to top
Jonathan Benedicto
Guest





PostPosted: Thu Jan 20, 2005 3:37 pm    Post subject: Re: Slow scanline Reply with quote

I'm sorry for not trimming the quotes.

I was thinking of something like this :

int x, iGrey, xl = CAMRESX * 3;
float r, g, b;
BYTE* pLine;

for(int y=0;y<CAMRESY;y++){
pLine = (BYTE*) ((THackJPEGImage*)JPEGImage)->Bitmap->ScanLine[y];

for(x=0;x<xl;x+=3){
r = pLine[x];
g = pLine[x + 1];
b = pLine[x + 2];

iGrey = b * 0.11 + g * 0.59 + r * 0.30;
pData8Out[(x / 3) + yoffsOut] = iGrey;
}

yoffsOut += CAMRESX;
}

--
Jonathan

"Hans Galema"
Quote:
You mean something like:

Hans.



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.