Ask Your Question
0

error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK

asked 2014-08-20 06:07:34 -0500

Olivier gravatar image

Bonjour, Je souhaite détecter le mouvement des nuages sur une vidéo avec Python. Pour cela je choisis 2 images espacées de quelques secondes dans cette vidéo. Ensuite je détecte les points d'intérets dans les deux images avec goodFeaturesToTrack() Enfin, je veux utiliser calcOpticalFlowPyrLK(). Je rencontre l'erreur que je vous ai mise en titre. Le code est ci-dessous

Merci pour votre aide

Code_1.png Code_2.png

edit retag flag offensive close merge delete

Comments

can you try again, in english, please ?

also, if you got code, paste that here, not a screenshot. (so people can play with your code)

and please, read the faq

berak gravatar imageberak ( 2014-08-20 06:24:44 -0500 )edit

btw, error means, that your prevPtsMat was empty

berak gravatar imageberak ( 2014-08-20 08:15:07 -0500 )edit

2 answers

Sort by » oldest newest most voted
0

answered 2014-08-24 08:28:01 -0500

Olivier gravatar image

Ok I found my mistake. In the detection_coins() dunction I changed into integers the corners coordonates. I changed that and I don't have this error anymore. Now Ihave the following error when I use the cv.imshow() function at the lasts lines of my program to see image_flow :

Traceback (most recent call last):
  File "/Users/oliviersamin/Documents/Projets_perso/Projet_FORSOLAR/Developement/Traitement image/Premier developpement/Photos_References/essai.py", line 101, in <module>
    cv.imshow("image avec flow",image_flow)
error: /tmp/opencv-tjJs/opencv-2.4.9/modules/highgui/src/utils.cpp:611: error: (-15) Source image must have 1, 3 or 4 channels in function cvConvertImage

Any help with that?

edit flag offensive delete link more
0

answered 2014-08-24 07:35:19 -0500

Olivier gravatar image

Hello, I'd like to detect clouds movement filmed with a camera. I'm coding with Python. To do so, I choose two different pictures from this film. Next I detect the interesting points with the goodFeaturesToTrack() function. At last, I'd like to use the calcOpticalFlowPyLK() function. When I'm using the last function and I'm meeting the errror that's in title. You'll find the code underneath :

#-*-coding:utf-8-*-

import cv2 as cv
import sys
import numpy as np
import time as time

##### Paramètres variables à entrer #######

nom_video="IMG_0595.mp4"
path="/Users/oliviersamin/Documents/Projets_perso/Projet_FORSOLAR/Developement/Traitement image/Premier developpement/Photos_References"
nom=path+"/"+nom_video


duree=5
nombre_coins=10

### Fonctions ####
def sauvegarde(nom_fichier,image):
    cv.imwrite(nom_fichier,image)

def chargement(nom_fichier):
    data=np.loadtxt(nom_fichier)
    return(data)

def ouverture_image(nom):
    #image=cv.imread('IMG_book.png',1)
    image=cv.imread(nom,1)
    return (image)

def HSV_masque_bleu(image):
    hsv = cv.cvtColor(image, cv.COLOR_BGR2HSV)
    low_b=np.array([107,50,50])
    high_b=np.array([125,255,255])
    maskb=cv.inRange(hsv,low_b,high_b)
    resb_and=cv.bitwise_and(image,image, mask= maskb)
    return(resb_and)

def gris(resb_and):
    bgr=cv.cvtColor(resb_and, cv.COLOR_HSV2BGR) # etape HSV -> BGR
    gray=cv.cvtColor(resb_and, cv.COLOR_BGR2GRAY) # etape BGR -> GRAY
    return(gray)

def seuillage(gray):
    ret,th_b = cv.threshold(gray,10,255,cv.THRESH_BINARY)# tout ce qui est au dessus de 10 passe en blanc
    th=255-th_b #j'inverse pour avoir les nuages blanc et le ciel noir
    return(th,th_b)

def detection_coins(th_b,image,nombre_coins):
    #feature_params=dict(maxCorners=100,qualityLevel=0.3,minDistance=7,blockSize=7)
    corners=cv.goodFeaturesToTrack(th_b,nombre_coins,0.00001,1)
    #corners=cv.goodFeaturesToTrack(th_b,mask=None,**feature_params)
    corners=np.int0(corners)
    for i in corners:
        x,y=i.ravel()
        cv.circle(image,(x,y),3,0,-1)
    return(image,corners)


def verifs(th,image,num):
    cv.imshow('threshold binaire'+str(num),th)
    cv.imshow('image avec coins detectes'+str(num),image)
##    cv.waitKey(0)
##    cv.destroyAllWindows()

def calcul_trajectoire(im1,im2,coins):
    test,st,err=cv.calcOpticalFlowPyrLK (im1,im2,coins)
    return (test)

def choix_images(nom,duree):
    cap = cv.VideoCapture(nom)
    cap.open(nom)
    test=[]
##    boucle=0
    t0=time.localtime()
    d=0
    while(d<duree):
##        print "boucle ",str(boucle+1)
        ret,frame = cap.read()
        test.append(frame)
##        cv.imshow('frame',frame)
##        boucle+=1
        t=time.localtime()
        d=t.tm_sec-t0.tm_sec
    return (test[0],test[-1])

##### prog principal #######

image1,image2=choix_images(nom,duree)
im1=HSV_masque_bleu(image1) 
im2=HSV_masque_bleu(image2) 
gris1=gris(im1)
gris2=gris(im2)
nb1,nb1_inv=seuillage(gris1)
nb2,nb2_inv=seuillage(gris2)
i1,c1=detection_coins(nb1_inv,image1,nombre_coins)
i2,c2=detection_coins(nb2_inv,image2,nombre_coins)
image_flow=calcul_trajectoire(image1,image2,c1)
##verifs(nb1,i1,1)
##verifs(nb2,i2,2)
cv.imshow("image avec flow",image_flow)
cv.waitKey(0)
cv.destroyAllWindows()

Thanks for your help

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2014-08-20 06:07:34 -0500

Seen: 8,331 times

Last updated: Aug 24 '14