Welcome, Guest. Please Login.
Surveyor Corporation Surveyor SRV-1
Home Help Search Login

Surveyor Robotics Forum

Welcome to the user support forum for Surveyor SRV-1 robots, SRV-1 robot controllers and SVS stereo vision systems. To register for this forum, please send an email to support@surveyor.com which includes your desired forum user name, your registration email address, and a brief explanation of why you wish to join, and we will create a forum account for you.

Please note that there is a Search button in the forum toolbar for forum topics. Another effective search method for the entire surveyor.com site is to use Google, e.g. "xyz site://www.surveyor.com" where "xyz" is the search topic.



Pages: 1 2 3 
Send Topic Print
Always getting the same value (Read 7999 times)
forsaqn
Junior Member
**




Posts: 92
Always getting the same value
07/07/09 at 3:50am
 
Im trying to do my coding modifying the myfunc.c
Im always getting the same value.
 
what I do(problably wrong) is to get a frame, calculate the differences and then check if the yuv values are over a given threshold.
 
heres part of the code
 
void myfunc() {
   unsigned int  ix,xx, yy, y1, u1, v1, sumx, sumy;
   
    unsigned char *frame_buf;
    y1 = u1=v1 =xx=0; yy=0;  sumx=0; sumy =0;
    grab_reference_frame() ;
    move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF, imgWidth, imgHeight);
    compute_frame_diff((unsigned char *)FRAME_BUF,  (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);  
     
   
 for (xx=0; xx<imgWidth; xx+=2) {    
       for (yy=0; yy<imgHeight; yy++) {
       ix = index(xx,yy);  
           y1 = (((unsigned int)frame_buf[ix+1] + (unsigned int)frame_buf[ix+3]));
           u1 = ((unsigned int)frame_buf[ix]);
           v1 = ((unsigned int)frame_buf[ix+2]);
           
           if(y1+u1+v1> 80){
               sumx=sumx+1;}          
                         
         
       }
    }
    printf(" %x", sumx);
     
    return;
}
 
thanks
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Always getting the same value
Reply #1 - 07/07/09 at 7:21am
 
Where are you saving a reference image to FRAME_BUF2 ?
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
forsaqn
Junior Member
**




Posts: 92
Re: Always getting the same value
Reply #2 - 07/07/09 at 8:20am
 
 need to create a char pointer and initialize it to frame_buf or frame_buf2
right?
   
    unsigned char *frame_buf, *frame_buf2;
    frame_buf = FRAME_BUF;
    frame_buf2 = FRAME_BUF2;
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Always getting the same value
Reply #3 - 07/07/09 at 9:16am
 
You need to first capture a reference frame before you can start comparing frames.  To capture a reference frame to FRAME_BUF2, use
 
move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
forsaqn
Junior Member
**




Posts: 92
Re: Always getting the same value
Reply #4 - 07/07/09 at 8:17pm
 
i still get the same value, i think im doing sth wrong here. Should i use grab_frame or grab_referece frame again?
 
extern unsigned int imgWidth, imgHeight;
 
void myfunc() {
   unsigned int  ix,xx, yy, y1, u1, v1, sumx, sumy;
  
    unsigned char *frame_buf, *frame_buf2;
    frame_buf = FRAME_BUF;
    frame_buf2 = FRAME_BUF2;
    y1 = u1=v1 =xx=0; yy=0;  sumx=0; sumy =0;
    grab_reference_frame() ;
    move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF, imgWidth, imgHeight);
    move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);
    compute_frame_diff((unsigned char *)FRAME_BUF,  (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);  
        
 for (xx=0; xx<imgWidth; xx+=2) {    
        for (yy=0; yy<imgHeight; yy++) {
        ix = index(xx,yy);  
            y1 = (((unsigned int)frame_buf[ix+1] + (unsigned int)frame_buf[ix+3]));
            u1 = ((unsigned int)frame_buf[ix]);
            v1 = ((unsigned int)frame_buf[ix+2]);
            
            if(y1+u1+v1> 80){
                sumx=sumx+1;}          
        }
    }
    printf(" %u", sumx);
    
    return;
}
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Always getting the same value
Reply #5 - 07/08/09 at 12:11am
 
Look at the source code in srv.c.  grab_reference_frame() is identical to  
   move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);
so there is no point in calling both.
 
Part of the problem is that you have no time delay capturing the reference frame and the new frame, so your code probably will not find any significant pixel differences.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
forsaqn
Junior Member
**




Posts: 92
Re: Always getting the same value
Reply #6 - 07/08/09 at 1:39am
 
Yes, that was what i saw. i modified the code and it works.
Now i want to get the centroid but i get strange values when i print the division of 2 unsigned ints.
how could i just print it out without decimal number. i just want the values that are before of the point.
 
thanks
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Always getting the same value
Reply #7 - 07/08/09 at 7:34am
 
I don't see any divides in your code.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
forsaqn
Junior Member
**




Posts: 92
Re: Always getting the same value
Reply #8 - 07/08/09 at 7:54pm
 
here is the code. i get strange values.
 
void myfunc() {
   unsigned int  ix,xx, yy, y1, u1, v1, sumx, sumy,totalpix, centerx,centery;
   
    unsigned char *frame_buf, *frame_buf2;
   frame_buf = FRAME_BUF;
    frame_buf2 = FRAME_BUF2;
     
    // grab_frame() ;
     
   while(1){
    grab_reference_frame() ;
    compute_frame_diff((unsigned char *)FRAME_BUF,  (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);  
  //  move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF, imgWidth, imgHeight);
    //move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);
    //compute_frame_diff((unsigned char *)FRAME_BUF,  (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);  
      y1 = u1=v1 =xx=0; yy=0;  centerx=centery=totalpix =sumx=0; sumy =0;
 for (xx=0; xx<imgWidth; xx+=2) {    
       for (yy=0; yy<imgHeight; yy++) {
       ix = index(xx,yy);  
           y1 = (((unsigned int)frame_buf[ix+1] + (unsigned int)frame_buf[ix+3]));
           u1 = ((unsigned int)frame_buf[ix]);
           v1 = ((unsigned int)frame_buf[ix+2]);
           
           if(y1>80 && u1> 30 && v1> 30){
              sumx=sumx+xx;      
              sumy=sumy+yy;    
              totalpix=totalpix+1;
      /* printf(" %u", y1);*/ }
    }}
    centerx=sumx/totalpix;  
    centery=sumy/totalpix;
    if (sumx>0 && sumy>0){printf(" &&& x:%u y:%u totalpix:%u  &&&",centerx,centery,totalpix );}
   
    move_image((unsigned char *)DMA_BUF1, (unsigned char *)DMA_BUF2, (unsigned char *)FRAME_BUF, imgWidth, imgHeight)  ;
    }return;
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Always getting the same value
Reply #9 - 07/08/09 at 10:39pm
 
You need to grab the reference frame just once, and then grab the current frame in your loop and call compute_frame_diff().  You have commented all of the calls to capture a current frame.  The difference pixels will be in FRAME_BUF2 after you call compute_frame_diff(), but you are using data from FRAME_BUF.
 
 
 
Back to top
 
« Last Edit: 07/08/09 at 10:41pm by admin »  

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
forsaqn
Junior Member
**




Posts: 92
Re: Always getting the same value
Reply #10 - 07/08/09 at 10:53pm
 
I would like to compare 2 consecutive frames.
for example eve 20 seconds.  
How could i store Frame_BUF into FRAME_BUF2 and from there compare the differences
then capture a new frame and store it in Frame_BUF and compare it to FRAME_BUF2.
this way i only need to take one picture not 2 .
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Always getting the same value
Reply #11 - 07/08/09 at 11:09pm
 
Your while(1) statement has the comparisons occurring continuously and at a very high rate.
 
Recent versions of firmware have a copy_image() function, but you could just use memcpy().  Make certain you are copying imgWidth * imgHeight * 2 bytes.
 
Contents of FRAME_BUF2 are overwritten by compute_frame_diff().  So it sounds like you want to first compute_frame_diff(), and then memcpy() or copy_image() from FRAME_BUF to FRAME_BUF2
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
forsaqn
Junior Member
**




Posts: 92
Re: Always getting the same value
Reply #12 - 07/09/09 at 12:49am
 
I didnt find the copy_image() function so i used  
 
memcpy(FRAME_BUF,FRAME_BUF2,sizeof(imgWidth * imgHeight * 2));
 
 
but seems its not working.
 
void myfunc() {
   unsigned int  ix,xx, yy, y1, u1, v1, sumx, sumy,totalpix, centerx,centery;
   
    unsigned char *frame_buf, *frame_buf2;
   frame_buf = FRAME_BUF;
    frame_buf2 = FRAME_BUF2;
     
     grab_frame() ;
     
   while(1){
    grab_reference_frame() ;
    compute_frame_diff((unsigned char *)FRAME_BUF,  (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);  
   
     
      y1 = u1=v1 =xx=0; yy=0;  centerx=centery=totalpix =sumx=0; sumy =0;
 for (xx=0; xx<imgWidth; xx+=2) {    
       for (yy=0; yy<imgHeight; yy++) {
       ix = index(xx,yy);  
           y1 = (((unsigned int)frame_buf[ix+1] + (unsigned int)frame_buf[ix+3]));
           u1 = ((unsigned int)frame_buf[ix]);
           v1 = ((unsigned int)frame_buf[ix+2]);
           
           if(y1>80 && u1> 30 && v1> 30){
              sumx=sumx+xx;      
              sumy=sumy+yy;    
              totalpix=totalpix+1;
      /* printf(" %u", y1);*/ }
    }}
    centerx=sumx/totalpix;  
    centery=sumy/totalpix;
    if (sumx>0 && sumy>0){printf(" &&& x:%u y:%u totalpix:%u  &&&",centerx,centery,totalpix );}
   
    memcpy(FRAME_BUF,FRAME_BUF2,sizeof(imgWidth * imgHeight * 2));
    }return;
     
     
}
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: Always getting the same value
Reply #13 - 07/09/09 at 7:14am
 
Try changing
 
grab_frame() ;
     
   while(1){
    grab_reference_frame() ;
    compute_frame_diff((unsigned char *)FRAME_BUF,  (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);  
   
 
to
 
grab__reference_frame() ;
     
   while(1){
    grab_frame() ;
    compute_frame_diff((unsigned char *)FRAME_BUF,  (unsigned char *)FRAME_BUF2, imgWidth, imgHeight);  
   
In any case, you will still have the problem that there is virtually no delay between consecutively captured frames, but this should detect small changes.  
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
forsaqn
Junior Member
**




Posts: 92
Re: Always getting the same value
Reply #14 - 07/09/09 at 7:53pm
 
Is there any way to control the frames per second so it could work, or with the use of a timer.
I would like  at most to capture 8 frames per second. How could i do this?
Back to top
 
 
  IP Logged
Pages: 1 2 3 
Send Topic Print