+ Post New Thread
Results 1 to 8 of 8
  1. #1
    Member level 1
    Points: 568, Level: 5

    Join Date
    Jun 2016
    Posts
    35
    Helped
    0 / 0
    Points
    568
    Level
    5

    Edge detection, which parameter used for get autofocus working ?

    Hello everyone PlS help !!!

    Is that is same FrameEdgeCount with summa in a following code ? or how to make this ?
    Frame edge count i found in youtube in 2:41 . I want to use it to make autofocus for my camera. Code from github ,

    Code:
     architecture Behavioral of edge_sobel is
    begin
    	edge_sobel: process (pclk_i)
    	
    		variable summax, summay : std_logic_vector(10 downto 0);
    		variable summa1, summa2 : std_logic_vector(10 downto 0);
    		variable summa          : std_logic_vector(10 downto 0);
    		
    	begin  
    		if (pclk_i'event and pclk_i = '1') then 
    			
    			rsync_o <= rsync_i;
    			fsync_o <= fsync_i;
    			
    		if fsync_i = '1' then			
    			if rsync_i = '1' then			
    															-- x2
    				summax:=("000" & pdata3)+("00" & pdata6 & '0')+("000" & pdata9)
    					-("000" & pdata1)-("00" & pdata4 & '0')-("000" & pdata7);
    															-- x2
    				summay:=("000" & pdata7)+("00" & pdata8 & '0')+("000" & pdata9)
    					-("000" & pdata1)-("00" & pdata2 & '0')-("000" & pdata3);
    				
    				-- Here is computed the absolute value of the numbers
    				if summax(10)='1' then
    					summa1:= not summax+1;
    				else
    					summa1:= summax;				
    				end if;
    
    				if summay(10)='1' then
    					summa2:= not summay+1;
    				else
    					summa2:= summay;
    				end if;
    				
    				summa:=summa1+summa2;
    				
    				summa_out<=summa;
    				-- Threshold = 127
    				if summa>"00001111111" then			
    					pdata_o<=(others => '1');
    				else 
    					pdata_o<=summa(DATA_WIDTH-	1 downto 0);
    				end if;
    				
    			END IF;
    		end if;
    Sobel fileter result , has some display problem cannot find out why.Click image for larger version. 

Name:	frameedgesumm.png 
Views:	9 
Size:	45.4 KB 
ID:	145130

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 5
    Points: 36,169, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,614
    Helped
    1927 / 1927
    Points
    36,169
    Level
    46

    Re: Edge detection, which parameter used for get autofocus working ?

    I dont understand the quesiton? can you please rephrase exactly what the problem is?



  3. #3
    Member level 1
    Points: 568, Level: 5

    Join Date
    Jun 2016
    Posts
    35
    Helped
    0 / 0
    Points
    568
    Level
    5

    Re: Edge detection, which parameter used for get autofocus working ?

    Quote Originally Posted by TrickyDicky View Post
    I dont understand the quesiton? can you please rephrase exactly what the problem is?
    what value or what variable need to be use from edge detection code to send to servo or stepper motor controller to regulate auto focus ?



    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 61,937, Level: 60
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    12,620
    Helped
    2926 / 2926
    Points
    61,937
    Level
    60

    Re: Edge detection, which parameter used for get autofocus working ?

    Hi,

    you may focus on background and you may focus on foreground. Thus you need to specify the area of interest.

    Generally sharper edges means a higher frequency range.
    Thus a high pass filter (or differentiation) plus some kind of calculatein about the high pass filtered ampliltude (like RMS) should do the job.

    I assume if you search the internet you will find optimized focus caclulation methods.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  5. #5
    Full Member level 4
    Points: 1,856, Level: 10

    Join Date
    May 2014
    Posts
    223
    Helped
    22 / 22
    Points
    1,856
    Level
    10

    Re: Edge detection, which parameter used for get autofocus working ?

    what value or what variable need to be use from edge detection code to send to servo or stepper motor controller to regulate auto focus ?
    Pulse width modulation? Surely your stepper motor controller has a datasheet?

    I would imagine you have some threshold from the sorbel filter. For example here we have a blob - window - of values exceeding threshold, therefore we adjust motor, until blob is sharp line.



    •   AltAdvertisment

        
       

  6. #6
    Member level 1
    Points: 568, Level: 5

    Join Date
    Jun 2016
    Posts
    35
    Helped
    0 / 0
    Points
    568
    Level
    5

    Re: Edge detection, which parameter used for get autofocus working ?

    no good experience in vhdl
    when so many edges , it mean camera best focused, so I think need to just invert data and summ for every frame.. pls help with code .
    when video = '1' video is std_logic
    x_int integer range from 0 to 639
    y_int integer range from 0 to 479
    DATA_O - output from sobel filter
    sim is unsigned
    sim_out also unsigned
    data_int <= to_unsigned(DATA_O);
    process(clk26)
    begin
    if rising_edge(clk26) then
    if video = '1' then
    sim:=sim+data_int;
    if y_int = 478 then
    sim_out<=sim;
    if y_int = 479 then
    sim:=(others => 0);
    sim_out:=(others => 0);
    end if;
    end if;
    end if;
    end if;
    end process;



  7. #7
    Full Member level 4
    Points: 1,856, Level: 10

    Join Date
    May 2014
    Posts
    223
    Helped
    22 / 22
    Points
    1,856
    Level
    10

    Re: Edge detection, which parameter used for get autofocus working ?

    Woah, hold up.

    Do you know the difference between variables and signals?

    Also please use indentation. That way you can see logical errors - see nested if below

    Code VHDL - [expand]
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    
    data_int <= to_unsigned(DATA_O); 
     process(clk26)
     begin
       if rising_edge(clk26) then
         if video = '1' then
           sim:=sim+data_int;  -- This is a variable assignment? Is your variable local/shared?.
           if y_int = 478 then
             sim_out<=sim;
             if y_int = 479 then -- This is a nested IF, It is only analysed if parent if is true. Since parent implies this is false it will never execute.
               sim:=(others => 0);
               sim_out:=(others => 0);
             end if;
           end if;
         end if;
       end if;
     end process;

    Look at comments I've placed inside



  8. #8
    Member level 1
    Points: 568, Level: 5

    Join Date
    Jun 2016
    Posts
    35
    Helped
    0 / 0
    Points
    568
    Level
    5

    Re: Edge detection, which parameter used for get autofocus working ?

    Hello , from VGA controller coming x and y , x is rows which is from 0 to 639 and y is a row's summ of x, from 0 to 479, so it need to find summ of all Data_int when video is equal to 1,



--[[ ]]--