def slot_on_loadTrajectory(self):
     fidxPath=self.editPath.text()
     ftrjPath="%s_trjfp.csv" % fidxPath
     if (not os.path.isfile(fidxPath)) or (not os.path.isfile(ftrjPath)):
         msg=q4.QMessageBox()
         msg.setText("Cant find idx-file [%s] or [%s]" % (fidxPath, ftrjPath) )
         msg.exec_()
     else:
         cap=ph.VideoCSVReader(str(fidxPath))
         numFrames=cap.getNumFrames()
         arrTrj=np.genfromtxt(ftrjPath, delimiter=',')
         # assert arrTrj.shape[0]==numFrames
         numFramesGood=min(arrTrj.shape[0], numFrames)
         # numFramesGood=100
         self.progress.setMinimum(0)
         self.progress.setMaximum(numFramesGood-1)
         for ii in xrange(numFramesGood):
             tret,timg=cap.read(ii)
             if tret:
                 pxm=convertMat2Pixmap(timg)
                 self.appendImage(pxm, (arrTrj[ii,0],arrTrj[ii,1]), arrTrj[ii,2], arrTrj[ii,3])
             self.progress.setValue(ii)
             q4.QApplication.processEvents()
def proc_seq():
    cap = ph.VideoCSVReader(fidx)
    cap.printInfo()
    for tt in listDet:
        print tt
        det = fp.getDetByName(tt)
        if det == None:
            print 'ERROR: incorrect detector [%s], exit...' % tt
            sys.exit(1)
        ret = True
        cap.resetPos()
        while ret:
            ret, frm, fname = cap.readWithName()
            if not ret:
                continue
            kp, kd = det.detectAndCompute(frm, None)
            frmc = cv2.cvtColor(frm.copy(), cv2.COLOR_GRAY2BGR)
            fp.plotFPoints(frmc, kp, rad=3)
            fkp = '%s_%s.kp' % (fname, tt)
            fimgOut = '%s_%s_kp.png' % (fname, tt)
            cv2.imwrite(fimgOut, frmc)
            fp.kp2file(fkp, kp, kd)
            print "--> %s : %s" % (tt, fkp)
Exemplo n.º 3
0
def calcCCHomography(imgBig, imgSmall, H):
    siz = imgSmall.shape
    borderSiz = (0.15 * np.array(siz)).astype(np.int)
    imgBigWarpCrop = cv2.warpPerspective(imgBig, np.linalg.inv(H),
                                         (siz[1], siz[0]))
    imgBigWarpCrop = imgBigWarpCrop[borderSiz[0]:-borderSiz[0],
                                    borderSiz[1]:-borderSiz[1]]
    imgSmallCrop = imgSmall[borderSiz[0]:-borderSiz[0],
                            borderSiz[1]:-borderSiz[1]]
    return calcCorrCoeff(imgBigWarpCrop, imgSmallCrop)


####################################
if __name__ == '__main__':
    dscName = 'SURF'
    cap0 = ph.VideoCSVReader(fvideo0)
    cap1 = ph.VideoCSVReader(fvideo1)
    numFrm0 = cap0.getNumFrames()
    numFrm1 = cap1.getNumFrames()
    #
    dir0 = os.path.basename(os.path.dirname(fvideo0))
    dir1 = os.path.basename(os.path.dirname(fvideo1))
    wdir = os.path.dirname(os.path.dirname(fvideo0))
    foutDstCorr = "%s/%s_match_to_%s.csv" % (wdir, dir0, dir1)
    #
    dstCorr = np.genfromtxt(foutDstCorr, delimiter=',')
    # plt.imshow(dstCorr)
    # plt.show()
    numFrm0 = dstCorr.shape[0]
    numFrm1 = dstCorr.shape[1]
    dirOut = '%s/%s_%s_matches' % (wdir, dir0, dir1)
Exemplo n.º 4
0
#!/usr/bin/python
__author__ = 'ar'

import cv2
import numpy as np
import libfp as fp
import libphcorr as ph


fvideo='/home/ar/video/UAV_PHONE/part_2/vid0_1to2.mp4_proc/idx.csv'

listDet=('BRISK', 'SURF', 'SIFT', 'ORB')

if __name__=='__main__':
    csvReader=ph.VideoCSVReader(fvideo)
    csvReader.printInfo()
    numf=csvReader.getNumFrames()
    algName='SURF'
    for ii in xrange(30,numf-1):

        print "%d/%d" % (ii, numf)
            fimgOut = '%s_%s_kp.png' % (fname, tt)
            cv2.imwrite(fimgOut, frmc)
            fp.kp2file(fkp, kp, kd)
            print "--> %s : %s" % (tt, fkp)


#############################
if __name__ == '__main__':
    #
    try:
        print affinity.get_process_affinity_mask(0)
        affinity.set_process_affinity_mask(0, 2**mp.cpu_count() - 1)
    except:
        pass
    #
    cap = ph.VideoCSVReader(fidx)
    cap.printInfo()
    taskManager = fp.TaskManager()
    for tt in listDet:
        print tt
        det = fp.getDetByName(tt)
        if det == None:
            print 'ERROR: incorrect detector [%s], exit...' % tt
            sys.exit(1)
        ret = True
        numFrames = cap.getNumFrames()
        for ii in xrange(numFrames):
            fname = cap.listFImg[ii]
            print 'Append task {%s}-[%s]' % (tt, fname)
            taskManager.appendTaskCalcKPF(fname, tt)
    taskManager.pool.close()
    def getTrj(self):
        return np.array(self.listTrj[1:])

    def printInfo(self):
        print self.getTrj()


def calcFrameKPScore(lstKP):
    kpResp = [xx.response for xx in lstKP]
    return (np.mean(kpResp), np.std(kpResp), len(lstKP))


###############################
if __name__ == '__main__':
    cap = ph.VideoCSVReader(fvideo)
    cap.printInfo()
    lstKP = []
    lstKD = []
    lstKPData = []
    numFrm = cap.getNumFrames()
    numFrm = 6
    totH = None
    homoBuff = HomoBuff(pcFrm)
    curlDefData = np.zeros((numFrm, 2))
    arrCoords = []
    imgOld = None
    imgCurr = None
    for ii in xrange(0, numFrm):
        fkp = cap.getKPByID(ii, dscName)
        kpData = fp.file2kp(fkp)