<commit_before>import cv2
import numpy as np

filename = 'Transport TestFlutter0.mp4'


def make_image_mask(img):
    # B G R
    lower_blue = np.array([0,0,120])# np.array([60,30,55])
    upper_blue = np.array([70,70,200])
    
    # Threshold the HSV image to get only blue colors
    thresh = cv2.inRange(img, lower_blue, upper_blue)
    
    cv2.imshow('mask', thresh)
    return thresh

def get_circle(frame): 
       
    side_mask = make_image_mask(frame)
    contours, hierarchy = cv2.findContours(side_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    
    print len(contours)
    cnt = contours[0]
    (x,y),radius = cv2.minEnclosingCircle(cnt)
    center = (int(x),int(y))
    radius = int(radius)
    side_mask = cv2.cvtColor(side_mask, cv2.COLOR_GRAY2RGB)
    #cv2.circle(side_mask, (447,63), 63, (0,0,255), -1)
    cv2.circle(side_mask, center, radius, np.array([0,0,255]), 10)
    cv2.imshow('mask', side_mask)
    print 'center: ', center, 'radius: ', radius, ' found from side camera'
    
###    return side_center, radius

    return 1, 2



##Open Video file:
cap = cv2.VideoCapture(filename) 

while(cap.isOpened()):
    ret, frame = cap.read()
    center, radius = get_circle(frame)

    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    #cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
<commit_msg>Super ugly, but functional at tracking marker & plotting<commit_after>import cv2
import numpy as np
import matplotlib.pyplot as plt
import pprint

filename = 'Transport TestFlutter0.mp4'

numberErrors = 0
centerP = 0; radiusP = 0;
frameNum = 0
centerArrayX = []; centerArrayY = []


def make_image_mask(img):
    # B G R
    lower_blue = np.array([0,0,120],  dtype=np.uint8)# np.array([60,30,55])
    upper_blue = np.array([70,70,200],  dtype=np.uint8)
    
    # Threshold the HSV image to get only blue colors
    ##print 'hi 1'
    try:
        ##print 'trying thresh'
        thresh = cv2.inRange(img, lower_blue, upper_blue)
        ##print 'thresh successful: '
        ##print thresh
        #cv2.imshow('mask', thresh)
        return thresh
    except:
        print "Fatal inRange error!"
        cv2.imshow('mask', img)
        return ''
    
    

def get_circle(frame): 
    global numberErrors
    global center
    global radius
    
    ##print 'b4 mask'
    side_mask = make_image_mask(frame)
    ##print 'made mask'
    if type(side_mask) != type(''):
        contours, hierarchy = cv2.findContours(side_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
        ##print 'found contrs'
        

        if len(contours):
            cnt = contours[0]
            (x,y),radius = cv2.minEnclosingCircle(cnt)
            center = (int(x),int(y))
            radius = int(radius)
            side_mask = cv2.cvtColor(side_mask, cv2.COLOR_GRAY2RGB)
            #cv2.circle(side_mask, (447,63), 63, (0,0,255), -1)
            
            #cv2.circle(side_mask, center, radius, np.array([0,0,255]), 10)
            #cv2.imshow('mask', side_mask)
            #print 'center: ', center, 'radius: ', radius, ' found from side camera'
            
#            return center, radius

#        else:
#            numberErrors = numberErrors + 1
#            print 'Current number of error frames is: ', numberErrors
#            return 0, 0



##Open Video file:
cap = cv2.VideoCapture(filename) 

while(cap.isOpened()):
    ret, frame = cap.read()
    #center, radius = 
    get_circle(frame)
    centerP, radiusP = center, radius
    
    if center: 
        centerArrayX.append(center[0])
        centerArrayY.append(center[1])
    else: 
        'In P block. centerP is: ', centerP
        centerArrayX.append(centerP[0])
        centerArrayY.append(centerP[1])
    #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    #cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    frameNum =frameNum + 1
    ##print 'Frame num is: ', frameNum
    if frameNum > 273:
        #pprint.pprint(centerArray)
        plt.plot(centerArrayX, label = 'X marker positon', color='#AA3C39', linewidth=6)
        plt.plot(centerArrayY, label = 'Y marker positon', color='#7A9E35', linewidth=6)
        plt.xlabel('Time', fontsize = 18)
        plt.ylabel('Pixel Position', fontsize = 18)
        plt.title('Position of Fluttering Sail Through Time', fontsize = 20)
        plt.legend()
        plt.show()

cap.release()
#cv2.destroyAllWindows()

{'fraction_non_alphanumeric': 0.13097106974657996, 'fraction_numerical': 0.036555281453240634, 'mean_word_length': 2.716666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '201007', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1551, 'n_words': 351}