Ask Your Question

Olivier's profile - activity

2019-09-01 11:03:57 -0600 received badge  Famous Question (source)
2019-09-01 11:03:57 -0600 received badge  Notable Question (source)
2018-11-02 08:52:10 -0600 received badge  Popular Question (source)
2014-08-24 08:28:01 -0600 answered a question error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK

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?

2014-08-24 07:35:19 -0600 answered a question error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK

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

2014-08-20 06:07:34 -0600 asked a question error: (-215) (npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0 in function calcOpticalFlowPyrLK

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