Example #1
0
    diffFrame = currentFrame - prevFrame;
    prevFrame = currentFrame;

    diffFrameAbs = np.absolute(diffFrame)

    frameVect = currentFrame.reshape(1,newSize[0]*newSize[1]);
    frameVectFloat = frameVect.astype(float);

    frRecShort = np.delete(frRec, 0, 0);
    frRec = np.vstack((frRecShort,frameVectFloat));

    sumFrRec = np.sum(frRec,0);
    
    posDic, maxMovement, cfrVectRec, frameVectFloatRec = getting_frame_record(frRec, 0, winST,fb);
  
    im3CRaw = create_3C_image (cfrVectRec)
        
    if np.count_nonzero(im3CRaw[:,:,0])>6400:            
        im3CRaw[:,:,0] = np.zeros((80,80))
        
    if np.count_nonzero(im3CRaw[:,:,1])>800:            
        im3CRaw[:,:,1] = np.zeros((80,80))
        
    rgbArray = np.zeros((80,80,3), 'uint8')
    rgbArray[..., 0] = im3CRaw[:,:,0]
    rgbArray[..., 1] = im3CRaw[:,:,1]
    rgbArray[..., 2] = im3CRaw[:,:,2]
    im3C = Image.fromarray(rgbArray)

    X_rs = np.zeros((1,80,80,3))
        
Example #2
0
    prevFrame = currentFrame

    diffFrameAbs = np.absolute(diffFrame)

    frameVect = currentFrame.reshape(1, newSize[0] * newSize[1])
    frameVectFloat = frameVect.astype(float)

    frRecShort = np.delete(frRec, 0, 0)
    frRec = np.vstack((frRecShort, frameVectFloat))

    # sumFrRec = np.sum(frRec,0);

    posDic, maxMovement, cfrVectRec, frameVectFloatRec = getting_frame_record(
        frRec, 0, winST, fb, newSize, roi, CVNsize)

    im3CRaw = create_3C_image(cfrVectRec, CVNsize)

    if np.count_nonzero(im3CRaw[:, :, 0]) > (roi * roi):
        im3CRaw[:, :, 0] = np.zeros((roi, roi))

    if np.count_nonzero(im3CRaw[:, :, 1]) > (roi * 10):
        im3CRaw[:, :, 1] = np.zeros((roi, roi))

    rgbArray = np.zeros((roi, roi, 3), 'uint8')
    rgbArray[..., 0] = im3CRaw[:, :, 0]
    rgbArray[..., 1] = im3CRaw[:, :, 1]
    rgbArray[..., 2] = im3CRaw[:, :, 2]
    im3C = Image.fromarray(rgbArray)

    # X_rs = np.zeros((1,roi,roi,3))
Example #3
0
def video_clips_to_3C_image_fun(dirPathInput, dirPathOutput, fbList, clipStart,
                                clipEnd, clipsNumber, bufferSize, windowST,
                                modelName, OSplatform, roi, CVNsize):

    if modelName != 'none':

        model = keras.models.load_model(modelName)

    clips = np.arange(clipFirst, clipsNumber, 1)

    fileList = os.listdir(dirPathInput)

    clIndex = 0

    for cl in clips:

        fileName = fileList[cl]

        ext = fileName[-3:]

        if (ext == 'avi' or ext == 'mov' or ext == 'mp4') == True:
            if OSplatform == 'Linux':
                fileDirPathInputName = dirPathInput + '/' + fileName
            if OSplatform == 'Windows':
                fileDirPathInputName = dirPathInput + '\\' + fileName
            if OSplatform == 'Darwin':
                fileDirPathInputName = dirPathInput + '/' + fileName

            r = np.arange(0, clipEnd, bufferSize)

            for bf in r:

                startFrame = bf
                endFrame = startFrame + bufferSize

                frRec = read_frames(startFrame, endFrame, fileDirPathInputName,
                                    newSize)  #resizes frame to newSize

                if clIndex == clips[0] and startFrame == clipStart:
                    frRecRemain = np.zeros(
                        (windowST, (int(newSize[0] * newSize[1]))))
                    #160000=400*400
                    frRec = np.concatenate((frRecRemain, frRec), axis=0)

                if clIndex > clips[0] or startFrame > clipStart:
                    frRec = np.concatenate((frRecRemain, frRec), axis=0)

                for fb in fbList:

                    recIm3C = np.zeros((bufferSize, CVNsize, CVNsize, 3))

                    for w in range(0, frRec.shape[0] - windowST):

                        startWin = w
                        endWin = startWin + windowST

                        posDic, maxMovement, cfrVectRec, frameVectFloatRec = getting_frame_record(
                            frRec, startWin, endWin, fb, newSize, roi, CVNsize)

                        im3C = create_3C_image(cfrVectRec, CVNsize)

                        if modelName != 'none':
                            predictBehavior = 1  # predict behavior from ST-image and store the label
                        else:
                            predictBehavior = 0

                        if predictBehavior == 1:

                            X_rs = np.zeros((1, CVNsize, CVNsize, 3))

                            X_rs[0, :, :, :] = im3C

                            X = X_rs / 256  # normalize

                            predictionsProb = model.predict(X)
                            predictionLabel = np.zeros(
                                (1, np.shape(predictionsProb)[0]))
                            predictionLabel[0, :] = np.argmax(predictionsProb,
                                                              axis=1)

                        #cv2.imshow('im3C',im3C)

                        recIm3C[w, :, :, :] = im3C

                        xPos = posDic["xPos"]
                        yPos = posDic["yPos"]

                        if w == 0:
                            global xPosRec  #AER
                            xPosRec = xPos
                            global yPosRec  #AER
                            yPosRec = yPos
                            global maxMovementRec  #AER
                            maxMovementRec = maxMovement

                            if modelName != 'none':
                                global behPredictionRec  #AER
                                behPredictionRec = predictionLabel
                            else:
                                behPredictionRec = 0

                        if w > 0:

                            xPosRec = np.vstack((xPosRec, xPos))
                            yPosRec = np.vstack((yPosRec, yPos))
                            maxMovementRec = np.vstack(
                                (maxMovementRec, maxMovement))

                            if modelName != 'none':
                                behPredictionRec = np.vstack(
                                    (behPredictionRec, predictionLabel))
                            else:
                                behPredictionRec = 0

                    xPosRec = 0  #AER
                    yPosRec = 0  #AER
                    dictPosRec = {
                        "xPosRec": xPosRec,
                        "yPosRec": yPosRec
                    }
                    maxMovementRec = 0  #AER
                    behPredictionRec = 0  #AER
                    dictST = {
                        "recIm3C": recIm3C,
                        "dictPosRec": dictPosRec,
                        "maxMovementRec": maxMovementRec,
                        "behPredictionRec": behPredictionRec
                    }

                    nameSMRec = 'dict3C_' + fileName[0:-4] + '_Arena1_' + str(
                        '%06.0f' % bf)

                    if OSplatform == 'Linux':
                        #newPath = dirPathOutput + '/' + fileName[0:-4] + '_fb' + str(fb)  #!!!!!!works with non-numbered clips (one clip per video recording)
                        newPath = dirPathOutput + '/' + fileName[
                            0:
                            -4] + '_Arena1'  #!!!!!!works with numbered clips (multiple clips of the same video; clip names end with index number)

                    if OSplatform == 'Windows':
                        #newPath = dirPathOutput + '\\' + fileName[0:-4] + '_fb' + str(fb)  #!!!!!!works with non-numbered clips (one clip per video recording)
                        newPath = dirPathOutput + '\\' + fileName[
                            0:
                            -4] + '_Arena1'  #!!!!!!works with numbered clips (multiple clips of the same video; clip names end with index number)

                    if OSplatform == 'Darwin':
                        #newPath = dirPathOutput + '/' + fileName[0:-4] + '_fb' + str(fb)  #!!!!!!works with non-numbered clips (one clip per video recording)
                        newPath = dirPathOutput + '/' + fileName[
                            0:
                            -4] + '_Arena1'  #!!!!!!works with numbered clips (multiple clips of the same video; clip names end with index number)

                    if not os.path.exists(newPath):
                        os.mkdir(newPath)
                    if OSplatform == 'Linux':
                        fileDirPathOutputName = newPath + '/' + nameSMRec
                    if OSplatform == 'Windows':
                        fileDirPathOutputName = newPath + '\\' + nameSMRec
                    if OSplatform == 'Darwin':
                        fileDirPathOutputName = newPath + '/' + nameSMRec

                    with open(fileDirPathOutputName, "wb") as f:
                        pickle.dump(dictST, f)

                frRecSh = frRec.shape
                frRecRemain = frRec[bufferSize:frRecSh[0], :]
            clIndex = clIndex + 1
            print(clIndex)