Exemplo n.º 1
0
jasf_cv.getSettingsWindow()

jasf.cv.setManyTrackbars(['low', 'upper'], [10, 25], [100, 100])
jasf.cv.setManyTrackbars(['low2', 'upper2'], [150, 50000], [10000, 50000])

while cam.isOpened():
    ch = cv2.waitKey(5) & 0xFFFF
    if ch == ord('q'):
        break

    ret, frame = cam.read()

    low_th, up_th = jasf.cv.readManyTrackbars(['low', 'upper'])
    low_th_area, up_th_area = jasf.cv.readManyTrackbars(['low2', 'upper2'])

    flowInput = jasf_cv.convertBGR2Gray(frame)
    oldP, newP = flowComputer.apply(flowInput)

    flowFilter.setTh(low_th, up_th)
    oldP, newP = flowFilter.apply(oldP, newP)

    flowFilter2.setTh(low_th_area, up_th_area)
    oldP, newP = flowFilter2.apply(oldP, newP, debugMode=True)

    flowImg = flowUtil.draw_flow(frame,
                                 oldP,
                                 newP, (255, 0, 0),
                                 1,
                                 1,
                                 2,
                                 th=0.2)
Exemplo n.º 2
0
                                         isColor=False)

    if writeDFT:
        #get video writer to write DFT of flowDiff
        DFTWriter = cv2.VideoWriter('./output/flowDiff_DFT.avi',
                                    cv2.VideoWriter_fourcc(*'XVID'),
                                    videoFrameRate, (ncols, nrows),
                                    isColor=False)

    if displayResults:
        #initialize windows to be used
        jasf.cv.getManyWindows(['input', 'flowDiffMag', 'flowDiffMagSpectrum'])

    #run spectral analysis in only one image gotten from the video
    if modeDemoSpectrum:
        gray = jasf_cv.convertBGR2Gray(frame)
        img = gray.copy()

        dft = cv2.dft(np.float32(img), flags=cv2.DFT_COMPLEX_OUTPUT)
        dft_shift = np.fft.fftshift(dft)

        magnitude_spectrum = 20 * np.log(
            cv2.magnitude(dft_shift[:, :, 0], dft_shift[:, :, 1]))

        maxM = magnitude_spectrum.max()
        minM = magnitude_spectrum.min()

        magnitude_spectrum = (magnitude_spectrum - minM) * 255.0 / maxM

        magnitude_spectrum = magnitude_spectrum.astype(np.uint8)
Exemplo n.º 3
0
    def update(self):
        #read frame
        ret, frame = self.cam.read()
        if ret == False:
            raise VideoInvalid('finishing due to end of video')
        left, right = devika_cv.break_left_right(frame)
        inputList = [left, right, frame]

        #read parameters from settings window
        settings = self.readSettingsParameters()
        th, th_max, area_delta, dilateSize, erodeSize, LRA = settings['th'], settings['max'], settings['delta'],\
                settings['dilateSize'], settings['erodeSize'], settings['LRA']


        #select which image to use
        input = inputList[LRA]
        h,w,d = input.shape
        ho, wo = 40,40
        extendedInput = np.zeros((h+2*ho,w+2*wo,d), dtype=np.uint8)
        extendedInput[ho:ho+h, wo:wo+w, :] = input[:,:,:]

        #get blue component(as suggested by Devika)
        B = input[:,:,0]
        Bextended = extendedInput[:,:,0]

        #-----------------------------------------------------------------
        #find candidates to rat contour
        #-----------------------------------------------------------------
        input = B.copy()
        self.contourFinder.setParams(dilateSize, erodeSize, th, th_max)
        contours, otsu_threshold, filterSmall = self.contourFinder.detectInterestingContours(input)

        #-----------------------------------------------------------------
        #Step 3: select which contour is the real mouse
        #-----------------------------------------------------------------
        rx,ry,new_mouse = self.contourPicker.pickCorrectContour(contours, {'last_center':(self.rx, self.ry), 'distanceRejectTh':2000})
        #if mouse was found, update parameters
        if type(new_mouse) is not bool:
            self.setMousePosition(rx,ry,new_mouse)
            self.updatedValuesOfTh(area_delta)

        #-----------------------------------------------------------------
        #Step 4: show output and some intermediate results
        #-----------------------------------------------------------------
        #draw countours
        output = Bextended.copy()
        #convert mouse coordinates to extended frame
        offset = np.empty_like(self.mouse)
        offset.fill(40)
        translatedMouse = self.mouse + offset
        #draw fixed dim rectangle around mouse
        output = jasf_cv.drawFixedDimAroundContourCenter(output, [translatedMouse], (200, 0, 200), np.array((60,60)))
        #get fixed lenght rectangle image
        mouseImg = jasf.cv.getRoiAroundContour(extendedInput, translatedMouse, dim = np.array((60,60)))

        mousePB = jasf_cv.convertBGR2Gray(mouseImg)
        oldP, newP = self.flowComputer.apply(mousePB)

        self.GUI.setImg(B, 0)
        self.GUI.setImg(255*otsu_threshold, 1)
        self.GUI.setImg(255*filterSmall, 2)
        self.GUI.setImg(output, 3)
        self.GUI.setImg(mouseImg, 4)
    ret,frame = cam.read()
    output = np.zeros_like(frame)

    jasf.cv.setManyTrackbars(['min', 'max'], [95, 100], [100,100])

    def readSettings():
        min,max = jasf.cv.readManyTrackbars(['min', 'max'])
        return min/100.0, max/100.0

    while True:
        ch = cv2.waitKey(30) & 0xFFFF
        if ch == ord('q'):
            break
        ret, frame = cam.read()
        frame = jasf_cv.convertBGR2Gray(frame)

        min,max = readSettings()
        unit.setPercentageInterval(min, max)

        old, new = unit.apply(frame)
        if old.size != 0:
            averageOld, averageNew = averageFlow(old, new)
            output = flowUtil.draw_flow(frame, old, new, drawArrows = True, lenghtOfArrayArm = 3)
            output = flowUtil.draw_flow(output, averageOld,averageNew, flowColor = jasf.cv.green, flowThickness=2,
                    drawArrows = True, lenghtOfArrayArm = 5)


        cv2.imshow('input', frame)
        cv2.imshow('output', output)
jasf.cv.setManyTrackbars(['low', 'upper'], [10, 25], [100, 100])
jasf.cv.setManyTrackbars(['low2', 'upper2'], [150, 50000], [10000, 50000])


while cam.isOpened():
    ch = cv2.waitKey(5) & 0xFFFF
    if ch == ord('q'):
        break
    
    ret, frame = cam.read()

    low_th, up_th = jasf.cv.readManyTrackbars(['low', 'upper'])
    low_th_area, up_th_area = jasf.cv.readManyTrackbars(['low2', 'upper2'])

    flowInput = jasf_cv.convertBGR2Gray(frame)
    oldP, newP = flowComputer.apply(flowInput)

    flowFilter.setTh(low_th, up_th)
    oldP, newP = flowFilter.apply(oldP, newP)

    flowFilter2.setTh(low_th_area, up_th_area)
    oldP, newP = flowFilter2.apply(oldP, newP, debugMode = True)


    flowImg = flowUtil.draw_flow(frame, oldP, newP, (255,0,0), 1, 1, 2, th = 0.2)

    cv2.imshow('input', frame)

cam.release()
cv2.destroyAllWindows()