Exemple #1
0
        break
    print(file)

    try:
        img = cv2.imread((input_img_folder + r"/" + file),
                         cv2.IMREAD_UNCHANGED)
        #    if cimg.shape[0] != 480:
        #        cimg = cv2.resize(cimg, (640,480))
        #    cimg = AF.rotateImage(cimg,180)
        #    img = cv2.cvtColor(cimg,cv2.COLOR_BGR2GRAY)
        #    img = cv2.GaussianBlur(img,(11,11),0)
        #img = cv2.erode(img, None, iterations=1)
        #img = cv2.dilate(img, None, iterations=1)

        #        img_mask=TH.colourmask(img,'red')
        circles_h = TH.h_method(img, 1, 50, 30, 15, 2, 15)
        circles_s = TH.s_method(img, 1, 100, 200, 22, 3, 20)
        circles_v = TH.v_method(img, 1, 50, 150, 11, 2, 15)
        circles_gray = TH.gray_method((input_img_folder + r"/" + file), 1, 50,
                                      150, 7, 1, 15)

        #        circles_h=TH.h_method(img,1,100,40,19,3,20)
        #        circles_s=TH.s_method(img,1,100,200,22,3,20)
        #        circles_v=TH.v_method(img,1,100,150,16,3,20)
        #        circles_gray=TH.gray_method((input_img_folder+r"/"+file),1,100,200,19,3,20)

        #        circles_h=TH.h_method(img,1,50,30,15,2,15)
        #        circles_s=TH.s_method(img,1,200,15,2,15)
        #        circles_v=TH.v_method(img,1,50,150,11,2,15)
        #        circles_gray=TH.gray_method((input_img_folder+r"/"+file),1,50,150,7,1,15)
        #
Exemple #2
0
    ##img_RGB= cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    ##
    ##    cimg = cv2.imread((file),cv2.IMREAD_UNCHANGED)
    ##    print(file)
    #    img= cv2.cvtColor(cimg, cv2.COLOR_BGR2RGB)
    try:
        #plt.figure('original')
        #imgplot = plt.imshow(img_RGB)
        img_blurred = cv2.GaussianBlur(img, (11, 11), 0)
        #hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV)
        #cv2.imshow('hsv',hsv)
        #plt.figure('HSV')
        #hsv_rgb = cv2.cvtColor(hsv, cv2.COLOR_BGR2HSV)
        #imgplot = plt.imshow(hsv_rgb)

        circles_h = TH.h_method(img_blurred, 1, 150, 130, 14, 5, 40)
        circles_s = s_method(img_blurred, 1, 150, 130, 15, 5, 40)
        circles_v = v_method(img_blurred, 1, 150, 150, 15, 5, 40)
        circles_gray = gray_method(str(file), 1, 150, 200, 10, 10, 40)

        all_pos_x, all_pos_y, all_radius = concatenate_results(
            method1=circles_h,
            method2=circles_s,
            method3=circles_v,
            method4=circles_gray)

        #    all_pos_valid_oldpos_x=Discard_if_too_far_from_old_pos(all_pos=all_pos_x,oldpos=260,thres_oldpos=50)
        #    all_pos_valid_oldpos_y=Discard_if_too_far_from_old_pos(all_pos=all_pos_y,oldpos=248,thres_oldpos=50)
        #    all_radius_valid_old=Discard_if_too_far_from_old_pos(all_pos=all_radius,oldpos=12,thres_oldpos=10)
        #
Exemple #3
0
save_images = True

counter=0

for file in files:    
    counter+=1
    if counter>500:
        break    
    print(file)

    try:
        img = cv2.imread((input_img_folder+r"/"+file),cv2.IMREAD_UNCHANGED)
      
        
        red_mask=TH.colourmask(img,'red')
        
        BLOB_pos,BLOB_dilated_img=TH.BLOB(red_mask)
        
    
#        red_mask_marked=np.copy(red_mask)
        red_mask_marked_three_channels = cv2.cvtColor(red_mask,cv2.COLOR_GRAY2RGB) 
        
        BLOB_pos = np.uint16(np.around(BLOB_pos))
        for i in BLOB_pos[:]:
            # draw the outer circle
    #            cv2.circle(img,(i[0],i[1]),i[2],(0,255,0),12)
            # draw the center of the circle
            cv2.circle(img,(i[0],i[1]),2,(0,255,0),10)
            cv2.circle(red_mask_marked_three_channels,(i[0],i[1]),2,(0,255,0),10)
        
Exemple #4
0
save_images = True

counter = 0

for file in files:
    counter += 1
    if counter > 200:
        break
    print(file)

    try:
        img = cv2.imread((input_img_folder + r"/" + file),
                         cv2.IMREAD_UNCHANGED)

        img_red_mask = TH.colourmask(img, 'red')

    except:
        print('No circles found in image: ', file)
        flag_BallFound = False
        consec_balls_found = 0
    #Save marked images
    if (save_images):
        try:
            AF.img_marked_saver(output_img_folder, image_format, img_No,
                                img_red_mask)
        except:
            print('Could not save image')
    img_No = img_No + 1
    img_marked.append(img_red_mask)
#os.chdir('C:/Users/Bruger/Documents/Uni/Abu dhabi/data/outdoor')
#img = cv2.imread('pica36.png')
cv2.destroyAllWindows()

os.chdir('C:/Users/Bruger/Documents/Uni/Abu dhabi/data/newvideo/video1_as_pic')
img = cv2.imread('video_574.png')

#img = cv2.imread('blob.jpg')
#gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#cimg = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
cimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.figure('orignal')
imgplot = plt.imshow(cimg)

img = TH.colourmask(img, 'red')

#cimg = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
plt.figure('mask')
imgplot = plt.imshow(img)

#blurred = cv2.medianBlur(img, 9)
#_filter = cv2.bilateralFilter(blurred, 5, 75, 75)
#adap_thresh = cv2.adaptiveThreshold(_filter,
#                                    255,
#                                    cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
#                                    cv2.THRESH_BINARY_INV,
#                                    21, 0)
#
element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
eroded = cv2.erode(img, element, iterations=3)
    img = cv2.GaussianBlur(img, (11, 11), 0)

    #img = cv2.erode(img, None, iterations=1)
    #img = cv2.dilate(img, None, iterations=1)

    #Find circles
    circles = cv2.HoughCircles(img,
                               cv2.HOUGH_GRADIENT,
                               1,
                               minDist=minDist,
                               param1=param1,
                               param2=param2,
                               minRadius=minRadius,
                               maxRadius=maxRadius)

    circles_h = TH.h_method(img, 1, 150, 130, 14, 5, 40)

    imgT = img.copy()
    blurred = cv2.GaussianBlur(
        imgT, (11, 11),
        0)  #Delte this line and import the blurred image directely
    hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV)

    h_part = hsv[:, :, 0]
    #cv2.imshow('h',h_part)  #Shows the original h part image of the hsv format
    iterations = 2
    h_part = cv2.erode(h_part, None, iterations=iterations)
    h_part = cv2.dilate(h_part, None, iterations=iterations)

    circles_h = cv2.HoughCircles(h_part,
                                 cv2.HOUGH_GRADIENT,
Exemple #7
0
os.chdir('C:/Users/Bruger/Documents/Uni/Abu dhabi/data/newvideo/video4_as_pic')

counter = 0
for filename in sorted(glob.glob('*.png'), key=os.path.getmtime):

    #for filename in glob.glob("*.png"): # This line take all the files of the filename .png from the current folder. Source http://stackoverflow.com/questions/6997419/how-to-create-a-loop-to-read-several-images-in-a-python-script
    counter += 1
    if counter > 10:
        break
#    col=Image.open(filename)
    img = cv2.imread(filename)

    #    circles_h=TH.h_method(img,1,150,130,14,5,40)
    #    circles_s=TH.s_method(img,1,150,130,15,5,40)
    circles_v = TH.v_method(img, 1, 150, 150, 15, 5, 40)
    circles_gray = TH.gray_method(filename, 1, 150, 200, 10, 10, 40)

    #circles_h=h_method(img,1,150,130,14,5,40)
    #circles_s=s_method(img,1,150,130,15,5,40)
    #circles_v=v_method(img,1,150,150,15,5,40)
    #circles_gray=gray_method(file_name_of_picture,1,150,200,10,10,40)

##    cimg = cv2.imread((input_img_folder+r"/"+file),cv2.IMREAD_UNCHANGED)
###    if cimg.shape[0] != 480:
###        cimg = cv2.resize(cimg, (640,480))
###    cimg = AF.rotateImage(cimg,180)
##    img = cv2.cvtColor(cimg,cv2.COLOR_BGR2GRAY)
##    img = cv2.GaussianBlur(img,(11,11),0)
#
##