+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Junior Member level 3
    Points: 493, Level: 4

    Join Date
    Jun 2016
    Posts
    31
    Helped
    0 / 0
    Points
    493
    Level
    4

    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:	8 
Size:	45.4 KB 
ID:	145130

    •   Alt6th March 2018, 11:38

      advertising

        
       

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

    Join Date
    Jun 2010
    Posts
    6,567
    Helped
    1914 / 1914
    Points
    35,892
    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?



    •   Alt6th March 2018, 12:55

      advertising

        
       

  3. #3
    Junior Member level 3
    Points: 493, Level: 4

    Join Date
    Jun 2016
    Posts
    31
    Helped
    0 / 0
    Points
    493
    Level
    4

    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 ?



    •   Alt6th March 2018, 15:11

      advertising

        
       

  4. #4
    Super Moderator
    Points: 57,700, Level: 58
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    11,765
    Helped
    2721 / 2721
    Points
    57,700
    Level
    58

    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. Thank you.



  5. #5
    Full Member level 4
    Points: 1,790, Level: 9

    Join Date
    May 2014
    Posts
    219
    Helped
    21 / 21
    Points
    1,790
    Level
    9

    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.



    •   Alt6th March 2018, 16:38

      advertising

        
       

  6. #6
    Junior Member level 3
    Points: 493, Level: 4

    Join Date
    Jun 2016
    Posts
    31
    Helped
    0 / 0
    Points
    493
    Level
    4

    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,790, Level: 9

    Join Date
    May 2014
    Posts
    219
    Helped
    21 / 21
    Points
    1,790
    Level
    9

    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



--[[ ]]--