Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1553 connectés 

  FORUM HardWare.fr
  Programmation
  Divers

  Problème Template matching matlab

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème Template matching matlab

n°1904988
donutsk8r
Posté le 13-07-2009 à 18:41:14  profilanswer
 

Bonjour,
 
Je suis actuellement en stage au Canada et mon maitre de stage souhaiterait que je réalise un programme matlab permettant de tracker un objet sur une video et ensuite déterminer sa vitesse et tracer sa trajectoire (dendrite en photo ci-jointe). Dans mon école d'ingénieur, la formation a matlab est loin d'être une priorité et donc j'ai un peu de mal à me lancer dessus.
 
En regardant sur un forum, j'ai trouvé ce programme qui avait été posté et qui correspondrait bien voire très bien à ce que je veux.
 

Code :
  1. % this code is able to track an object within a video, to plot the
  2. % trajectory and to calculate the velocity of the object
  3. % initialisations
  4. template_rows = 1;
  5. template_columns = 1;
  6. template_xmin = 1;
  7. template_ymin = 1;
  8. % importation of the video
  9. video = aviread('number 2.avi');
  10. % video_info is used to store the information about the video
  11. % (number of frames, format of frames, number of frames per second...)
  12. video_info = aviinfo('number 2.avi');
  13. NumFrames = video_info.NumFrames;
  14. FPS = video_info.FramesPerSecond;
  15. % the crop function is used here to extract the ultrasound image from all
  16. % frames
  17. % for example sometimes the frames have a Title and some comments that the
  18. % program doesn't need for the processing
  19. % this enables to reduce the running time of the program
  20. % the user selects a rectangle containing the ultrasound image
  21. [crop,rect_image2] = imcrop(video(1).cdata);
  22. % the loop extract the ultrasound image part of each frames
  23. for j=1:NumFrames
  24.     video(j).cdata = imcrop(video(j).cdata,rect_image2);
  25.     video(j).cdata = rgb2gray(video(j).cdata);
  26. end
  27. image1 = video(1).cdata;
  28. [frame_rows,frame_columns] = size(image1);
  29. % the crop function is used here to select the object that he is interested
  30. % in finding the trajectory and velocity of
  31. [template,rect_image1] = imcrop(image1);
  32. % the code below is saving informations about the rectangle selected by the
  33. % user (size, position ...)
  34. size_template = size(template);
  35. template_rows = size_template(1);
  36. template_columns = size_template(2);
  37. template_width = template_columns - 1;
  38. template_height = template_rows - 1;
  39. if rect_image1(1)<1
  40.     rect_image1(1)=1;
  41. end
  42. if rect_image1(2)<1
  43.     rect_image1(2)=1;
  44. end
  45. % the coordinates of the object are saved
  46. x_coordinates(1,1) = round(rect_image1(1))+((template_columns-1)/2);
  47. y_coordinates(1,1) = round(rect_image1(2))+((template_rows-1)/2);
  48. % the loop below computes the cross-correlation and finds the coordinates of
  49. % the object in all frames of the video
  50. for k=2:NumFrames
  51.     image2 = video(k).cdata;
  52.     corr = normxcorr2(template,image2);
  53.     % the program using the function max_corr
  54.     [corr_max_row,corr_max_column]=max_corr(corr);
  55.     % this part is computing the updating of the template
  56.     template_xmin = corr_max_column - template_width;
  57.     template_ymin = corr_max_row - template_height;
  58.     rect_template = [template_xmin, template_ymin, template_width, template_height];
  59.     template = imcrop(image2,rect_template);
  60.     % the coordinates of the object are saved
  61.     x_coordinates(1,k) = corr_max_column - ((template_columns-1)/2);
  62.     y_coordinates(1,k) = corr_max_row - ((template_rows-1)/2);
  63. end
  64. for i=1:NumFrames
  65.     y_coordinates(1,i)=frame_rows - y_coordinates(1,i);
  66. end
  67. % the program asks the user to enter the frame length scale
  68. Scale = input('Dimension of the frames (in mm):\n');
  69. % the pixel length and the time between two consecutive frames are
  70. % calculated
  71. pixel_length = Scale/frame_columns;
  72. deltaT = 1/FPS;
  73. % the loop below calculates the velocity of the object for each frames
  74. for k=2:NumFrames-1
  75.     offset_x = sqrt((x_coordinates(1,k+1)-x_coordinates(1,k-1))^2);
  76.     offset_y = sqrt((y_coordinates(1,k+1)-y_coordinates(1,k-1))^2);
  77.     velocity(1,k-1) = (sqrt(offset_x^2 + offset_y^2))/(2*deltaT);
  78. end
  79.        
  80. % this corresponds to the plotting of the trajectory 
  81.    
  82. subplot(2,1,1), plot(x_coordinates,y_coordinates,'o');
  83. axis([0 frame_columns 0 frame_rows]);
  84. xlabel('Pixels in the x axis');
  85. ylabel('Pixels in the y axis');
  86. title('trajectory of the object')
  87. subplot (2,1,2), plot(velocity);
  88. title ('velocity of the object');
  89. % the code below displays the velocity table
  90. velocity(:,:)


 
 
 Mais lorsque je tente de le lancer sur ma video, il y a un problème avec la fonction max_corr:
 
??? Undefined function or method 'max_corr' for input arguments of type 'double'.
 
Error in ==> vitesse at 85
[corr_max_row,corr_max_column]=max_corr(corr);
 
Cette fonction devait etre realiser par un programme indépendant de celui-ci. Quelqu'un de familier avec le template matching pourrait il m'expliquer ce que réalsie cette fonction?
 
merci beaucoup pour votre aide

mood
Publicité
Posté le 13-07-2009 à 18:41:14  profilanswer
 

n°1904993
Joel F
Real men use unique_ptr
Posté le 13-07-2009 à 20:01:42  profilanswer
 

max_corr effectue tres certainement un correletaion entre ta frame et le pattern a cherché et cherche le maximum de cette correlation dans l'image et renvoit les coordonnées.

n°1905037
donutsk8r
Posté le 13-07-2009 à 23:18:56  profilanswer
 

Mais cela correspond au numéro de la ligne et de la colonne du coefficient maximum de la matrice corr?

n°1905052
Joel F
Real men use unique_ptr
Posté le 14-07-2009 à 10:30:05  profilanswer
 

oui


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Divers

  Problème Template matching matlab

 

Sujets relatifs
Petites images et grandes images...VB 2008: problème de POO
problème de centrageProblème de height 100% et de position...
probleme de drop de table sur oracleProblème avec le rafraichissement d'une page
Inserer un tableau dans du php, problemeproblème de démarrage des applications
Problème image dans tableauprobleme de redirection nordnet
Plus de sujets relatifs à : Problème Template matching matlab


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR