2017-01-31 1 views
1

s'il vous plaît j'essaie de faire une nouvelle application en java pour assortir l'image et la vidéo, la correspondance du modèle dans l'image fonctionne bien, mais quand j'essaie de le faire pour la vidéo j'ai toujours cette erreur message:OpenCv correspondant modèle dans la vidéo [Java]

OpenCV Error: Assertion failed ((depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2) in cv::matchTemplate, file C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\templmatch.cpp, line 1062 Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: C:\builds\master_PackSlaveAddon-win64-vc12-static\opencv\modules\imgproc\src\templmatch.cpp:1062: error: (-215) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function cv::matchTemplate ]

Ceci est ma fonction pour faire correspondre la vidéo avec l'image, quelqu'un peut vous aider s'il vous plaît.

public int runVedio(String inFile, String templateFile, int match_method) { 
     int nbr = 0; 
     Mat templ = Imgcodecs.imread(templateFile); 

     VideoCapture capture=new VideoCapture(inFile); 
     Mat frame = new Mat(); 
     Mat result = new Mat(); 
     capture.read(frame); 

     ///Do the Matching and Normalize 
     Imgproc.matchTemplate(frame,templ, result, match_method); 
     Imgproc.threshold(result, result,0.9,1,Imgproc.THRESH_TOZERO); 

     //Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat()); 
     while(true) 
     { 
     ///Localizing the best match with minMaxLoc 
     Core.MinMaxLocResult mmr = Core.minMaxLoc(result); 

     Point matchLoc; 
     if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) { 
      matchLoc = mmr.minLoc; 
     } else { 
      matchLoc = mmr.maxLoc; 
     } 
     if(mmr.maxVal > 0.98) 
     { 
      ///Show me what you got 
      Imgproc.rectangle(frame, matchLoc, 
       new Point(matchLoc.x + templ.cols(),matchLoc.y + templ.rows()), 
       new Scalar(0,255,0),2); 
      Imgproc.rectangle(result, matchLoc, 
       new Point(matchLoc.x + templ.cols(),matchLoc.y + templ.rows()), 
       new Scalar(0,255,0),-1);  
      nbr++; 
     } 
     else 
     { 
      return nbr; 
     } 

     } 

    } 

Répondre

0

assurez-vous que vous accédez à la vidéo correctement pour que vous pouvez utiliser:

while(camera.read(frame)) 

Depuis, il est une vidéo que vous avez besoin d'accéder à toutes les images en elle afin de l'utiliser tout.

Et aussi votre image résultat i.e.

Mat result = new Mat(); 

doit aller comme ci-dessous, de sorte que les deux images sont de même taille et sont de même code couleur.

changer donc à cela,

new Mat(frame.rows(), frame.cols(), Highgui.CV_LOAD_IMAGE_COLOR); 

Exécutez le code et dites-moi MÉTÉO cela fonctionne ..