コード例 #1
0
ファイル: fin2.py プロジェクト: ssk-98/Ant-Bot-
def color_detect(img):
    '''
    #code for color Image processing to detect the color and shape of the 2 objects at max.
    #mentioned in the Task_Description document. Save the resulting images with the shape
    #and color detected highlighted by boundary mentioned in the Task_Description document.
    #The resulting image should be saved as a jpg. The boundary should be of 25 pixels wide.
    
    '''
    i = 1
    j = 3

    image = cv2.imread('Image1.jpg')
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    ret, threshold = cv2.threshold(gray, 0, 255,
                                   cv2.THRESH_BINARY + cv2.THRESH_OTSU)
    _, contours, _ = cv2.findContours(threshold, cv2.RETR_LIST,
                                      cv2.CHAIN_APPROX_NONE)
    cv2.drawContours(image, contours, i, (255, 0, 0), 25)
    cv2.drawContours(image, contours, j, (0, 255, 0), 25)

    result_image = image
    img = image[0:400, 0:400, :]

    aruco_list = detect_Aruco(img)

    M1 = cv2.moments(contours[i])
    cx1 = int(M1['m10'] / M1['m00'])
    cy1 = int(M1['m01'] / M1['m00'])

    M2 = cv2.moments(contours[j])
    cx2 = int(M2['m10'] / M2['m00'])
    cy2 = int(M2['m01'] / M2['m00'])

    tuple1 = (cx1, cy1)
    tuple2 = (cx2, cy2)

    calculate_Robot_State(img, aruco_list)
    mark_Aruco(img, aruco_list)

    print(tuple1)
    print(tuple2)

    font = cv2.FONT_HERSHEY_SIMPLEX
    cv2.putText(result_image, str(tuple1), (cx1, cy1), font, 0.5, (0, 0, 0), 2,
                cv2.LINE_AA)
    cv2.putText(result_image, str(tuple2), (cx2, cy2), font, 0.5, (0, 0, 0), 2,
                cv2.LINE_AA)

    cv2.imshow("ColorImage", result_image)
    cv2.imwrite("output_image4.jpg", result_image)
    cv2.waitKey(0)
コード例 #2
0
def aruco_detect(path_to_image):
    '''
    you will need to modify the ArUco library's API using the dictionary in it to the respective
    one from the list above in the aruco_lib.py. This API's line is the only line of code you are
    allowed to modify in aruco_lib.py!!!
    '''
    img = cv2.imread(
        path_to_image)  #give the name of the image with the complete path
    id_aruco_trace = 0
    det_aruco_list = {}
    img2 = img[0:400,
               0:400, :]  #separate out the Aruco image from the whole image
    cv2.imshow('frame', img2)
    det_aruco_list = detect_Aruco(img2)

    if det_aruco_list:
        img3 = mark_Aruco(img2, det_aruco_list)
        id_aruco_trace = calculate_Robot_State(img3, det_aruco_list)
        print(id_aruco_trace)
        cv2.imshow('image', img2)
        cv2.waitKey(0)

        #  Code for triggering color detection on ID detected

        cv2.destroyAllWindows()
コード例 #3
0
ファイル: Task1.2.py プロジェクト: bilalaziz786/Ant-bot
def aruco_detect(path_to_image):

    '''
    you will need to modify the ArUco library's API using the dictionary in it to the respective
    one from the list above in the aruco_lib.py. This API's line is the only line of code you are
    allowed to modify in aruco_lib.py!!!
    '''
    img = cv2.imread(path_to_image)     #give the name of the image with the complete path

    id_aruco_trace = 0
    det_aruco_list = {}
    img2 = img   #separate out the Aruco image from the whole image
    det_aruco_list = t.detect_Aruco(img2,img_name)
    if det_aruco_list:

        global idno
        for key in det_aruco_list.keys():
            idno = str(key)
            break

        img3 = t.mark_Aruco(img2,det_aruco_list)
        id_aruco_trace = t.calculate_Robot_State(img3,det_aruco_list)
        print(id_aruco_trace)        
        #cv2.imshow('image',img2)
        #cv2.waitKey(0)
    '''
    Code for triggering color detection on ID detected
    '''

    color_detect(img2) 
    
    cv2.destroyAllWindows()
コード例 #4
0
def aruco_detect(path_to_image):
    '''
    you will need to modify the ArUco library's API using the dictionary in it to the respective
    one from the list above in the aruco_lib.py. This API's line is the only line of code you are
    allowed to modify in aruco_lib.py!!!
    '''
    img = cv2.imread(
        path_to_image)  #give the name of the image with the complete path
    id_aruco_trace = 0
    det_aruco_list = {}
    det_aruco_list = aruco_lib.detect_Aruco(img)

    if det_aruco_list:
        img = aruco_lib.mark_Aruco(img, det_aruco_list)
        id_aruco_trace = aruco_lib.calculate_Robot_State(
            img[0], det_aruco_list)
        print(id_aruco_trace)
        cv2.imshow('image', img[0])
        cv2.waitKey(0)
    csvlist.append("ArUco" + path_to_image[-5] + ".jpg")
    csvlist.append(img[1])
    img8 = color_detect(img[0])
    cv2.imwrite("../Images/ArUco" + path_to_image[-5] + ".jpg", img8)
    #csvfile("Output.csv",['Image name','ArUco ID','(x,y)Object-1','(x,y)Object-2'])
    csvfile("../2535_Task1.2.csv", csvlist)

    cv2.destroyAllWindows()
コード例 #5
0
ファイル: Task1.2.py プロジェクト: bilalaziz786/Ant-bot
def custom_aruco_detect(path_to_image,n,C,color1,shape1,color2,shape2):

    img = cv2.imread(path_to_image)     #give the name of the image with the complete path

    id_aruco_trace = 0
    det_aruco_list = {}
    img2 = img   #separate out the Aruco image from the whole image
    det_aruco_list = custom_detect_Aruco(img2,n,C)
    if det_aruco_list:

        global idno
        for key in det_aruco_list.keys():
            idno = str(key)
            break

        img3 = t.mark_Aruco(img2,det_aruco_list)
        id_aruco_trace = t.calculate_Robot_State(img3,det_aruco_list)
        print(id_aruco_trace)        
        #cv2.imshow('image',img2)
        #cv2.waitKey(0)
    '''
    Code for triggering color detection on ID detected
    '''

    custom_color_detect(img2,color1,shape1,color2,shape2) 
    
    cv2.destroyAllWindows()
コード例 #6
0
ファイル: 400_Task1.2.py プロジェクト: pp-cyril/Ant-Bot-eYRC
def aruco_detect(path_to_image):
    '''
    you will need to modify the ArUco library's API using the dictionary in it to the respective
    one from the list above in the aruco_lib.py. This API's line is the only line of code you are
    allowed to modify in aruco_lib.py!!!
    '''
    img = cv2.imread(path_to_image)
    id_aruco_trace = 0
    det_aruco_list = {}

    det_aruco_list = aruco_lib.detect_Aruco(img)
    if (det_aruco_list):
        img3 = aruco_lib.mark_Aruco(img, det_aruco_list)
        id_aruco_trace = aruco_lib.calculate_Robot_State(img3, det_aruco_list)
        print(id_aruco_trace)
        k = str(id_aruco_trace)
        i = 1
        x = 0
        while (k[i] != ':'):
            x = x * 10 + int(k[i])
            i = i + 1
        print(x)
    global csv_arucoid
    csv_arucoid = str(x)

    color_detect(
        img)  #color detection and shape detection function triggered here
コード例 #7
0
ファイル: 183_Task1.2.py プロジェクト: WhiteWolf2077/Eyantra
def aruco_detect(path_to_image,shape1,color1,shape2,color2,i):
    '''
    you will need to modify the ArUco library's API using the dictionary in it to the respective
    one from the list above in the aruco_lib.py. This API's line is the only line of code you are
    allowed to modify in aruco_lib.py!!!
    '''
    img = cv2.imread(path_to_image)     #give the name of the image with the complete path
    
    id_aruco_trace = 0
    det_aruco_list = {}
    img2 = img[0:,0:,:]   #separate out the Aruco image from the whole image
    det_aruco_list = aruco.detect_Aruco(img2)
    if det_aruco_list:
        img3 = aruco.mark_Aruco(img2,det_aruco_list)
        id_aruco_trace = aruco.calculate_Robot_State(img3,det_aruco_list)
        for key, value in id_aruco_trace.items():
          print(key,value)
                
        cv2.imshow('image',img2)
        cv2.waitKey(0)
        '''
        Code for triggering color detection on ID detected
        ''' 
        color_detect(img2,shape1,color1,shape2,color2,i,key)
        cv2.destroyAllWindows()
コード例 #8
0
ファイル: arucoid.py プロジェクト: born-2learn/e-Yantra
def get_aruco_list():
    ids = []  # list to store Aruco IDs Scanned

    for frame in camera.capture_continuous(rawCapture,
                                           format="bgr",
                                           use_video_port=True):
        if len(ids) == 4:
            return ids
        # grab the raw NumPy array representing the image, then initialize the timestamp
        # and occupied/unoccupied text
        image = frame.array

        det_aruco_list = aruco_lib.detect_Aruco(image)
        if det_aruco_list:
            #print('Arduco detected')
            #image = aruco_lib.mark_Aruco(frame, det_aruco_list)
            robot_state = aruco_lib.calculate_Robot_State(
                image, det_aruco_list)
            id_raw = robot_state.keys()
            for i in id_raw:
                if i not in ids:
                    ids.append(i)
                    print('ID Detected:', i)
        #cv2.imshow("Frame", image)
        #key = cv2.waitKey(1) & 0xFF

        # clear the stream in preparation for the next frame
        rawCapture.truncate(0)
コード例 #9
0
ファイル: Task1.2 (1).py プロジェクト: muralisvishnu/eYantra
def aruco_detect(path_to_image):
    corners = []
    #comb = {50:0,100:1,250:2,1000:3}
    #num = (n-4)*4 + comb[c]
    img = cv2.imread(path_to_image)
    id_aruco_trace = 0
    arlist = aruco_lib.detect_Aruco(img)
    if arlist:
        img = aruco_lib.mark_Aruco(img, arlist)
        id_aruco_trace = aruco_lib.calculate_Robot_State(img, arlist)
        #cv2.imshow('k',img)
        #print(id_aruco_trace)
    org = cv2.imread(path_to_image)
    dup = cv2.cvtColor(org, cv2.COLOR_RGB2HSV)
    lower_red = np.array([110, 50, 50])
    upper_red = np.array([130, 255, 255])
    lower_green = np.array([33, 80, 40])
    upper_green = np.array([102, 255, 255])
    mask1 = cv2.inRange(dup, lower_red, upper_red)
    mask2 = cv2.inRange(dup, lower_green, upper_green)
    res = cv2.bitwise_or(mask1, mask2)
    ret, thresh = cv2.threshold(mask1, 127, 255, 1)
    im, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                               cv2.CHAIN_APPROX_SIMPLE)
    print(contours)
    cv2.drawContours(img, contours, 1, (0, 255, 0), 25)
    cv2.imshow("fra", img)
    ret1, thresh1 = cv2.threshold(mask2, 127, 255, 1)
    im, contours1, hierarchy = cv2.findContours(thresh1, cv2.RETR_TREE,
                                                cv2.CHAIN_APPROX_SIMPLE)
    cv2.drawContours(img, contours1, 1, (0, 0, 255), 25)
    cv2.imshow("fr", img)
    #cv2.imshow('k',mask1)
    #image3, contours, hierarchy = cv2.findContours(res,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE) #don't know why simple is not working only none seems to work and it does not deliver
    #the borders of the image have to be sharp, i'm seriously missing something
    #as i am not able to use the chain approx simple function to get the corners, i am also not able to calculate the values of the centroid
    #mask1 = cv2.cvtColor(mask1,cv2.COLOR_GRAY2RGB)
    #print(contours)
    #print(contours[2])
    '''
    for j in range(len(contours)):
        for i in contours[j]:
            cv2.circle(image,tuple(i[0]),1,(0,0,255),6)
    #cv2.imshow('final',image3)
    ''
    img = cv2.drawContours(img, contours[1], -1, (255,0,0), 25,cv2.LINE_AA)
    img = cv2.drawContours(img, contours[2], -1, (0,255,0), 25, cv2.LINE_AA)
    '''
    corners = cv2.goodFeaturesToTrack(mask1, 5, 0.01, 10)
    mask1 = cv2.cvtColor(mask1, cv2.COLOR_GRAY2RGB)
    print(tuple(corners[1][0]))
    for j in range(len(corners)):
        cv2.circle(mask1, tuple(corners[j][0]), 1, (0, 0, 255), 6)
    #cv2.imshow('final',image3)
    #cv2.imshow('final.jpg',res)
    print(corners)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
コード例 #10
0
def aruco_detect(path_to_image):

    img = cv2.imread(path_to_image)
    id_aruco_trace = 0
    det_aruco_list = {}
    img2 = img[0:425, 0:425, :]
    det_aruco_list = aruco_lib.detect_Aruco(img2, no)
    if det_aruco_list:
        img3 = aruco_lib.mark_Aruco(img2, det_aruco_list)
        id_aruco_trace, key = aruco_lib.calculate_Robot_State(
            img3, det_aruco_list)
        #print(key)
        return img, key
コード例 #11
0
def aruco_detect(img):
    id_aruco_trace = 0  #to store the state of the bot (centre(x), centre(y), angle)
    det_aruco_list = {
    }  #to store the detected aruco list dictionary with id and corners
    det_aruco_list = lib.detect_Aruco(
        img)  #detecting arucos in the given image
    if det_aruco_list:
        img3 = lib.mark_Aruco(img, det_aruco_list)
        id_aruco_trace = lib.calculate_Robot_State(img3, det_aruco_list)
        for x, y in id_aruco_trace.items():  #id value will be stored in x
            if (str(x).isnumeric()):
                if x not in ids:
                    print("ID detected: " + str(x))
                    ids.append(x)
コード例 #12
0
ファイル: arpi.py プロジェクト: WhiteWolf2077/Eyantra
def aruco_detect(path_to_image, i):

    img = cv2.imread(
        path_to_image)  #give the name of the image with the complete path
    id_aruco_trace = 0
    det_aruco_list = {}
    img2 = img[0:, 0:, :]  #separate out the Aruco image from the whole image
    det_aruco_list = aruco.detect_Aruco(img2)
    if det_aruco_list:
        img3 = aruco.mark_Aruco(img2, det_aruco_list)
        id_aruco_trace = aruco.calculate_Robot_State(img3, det_aruco_list)
        for key, value in id_aruco_trace.items():
            print(key, value)
            cv2.imshow('image', img2)
            cv2.waitKey(0)
            cv2.destroyAllWindows()
コード例 #13
0
def aruco_detect(path_to_image):
    '''
    you will need to modify the ArUco library's API using the dictionary in it to the respective
    one from the list above in the aruco_lib.py. This API's line is the only line of code you are
    allowed to modify in aruco_lib.py!!!
    '''
    img = cv2.imread(path_to_image)
    image=img.copy()
    #give the name of the image with the complete path
    id_aruco_trace = 0
    det_aruco_list = {}
    #img2 = img[0:x,0:y,:]   #separate out the Aruco image from the whole image
    det_aruco_list,k = li.detect_Aruco(img,path_to_image)
    if det_aruco_list:
        img3 = li.mark_Aruco(img,det_aruco_list)
        id_aruco_trace = li.calculate_Robot_State(img3,det_aruco_list)
        #p=id_aruco_trace.keys()
        print(k)
    color_detect(image,img3,path_to_image,k)
    return
コード例 #14
0
def color_detect(timg, s1, c1, s2, c2):
    '''
    code for color Image processing to detect the color and shape of the 2 objects at max.
    mentioned in the Task_Description document. Save the resulting images with the shape
    and color detected highlighted by boundary mentioned in the Task_Description document.
    The resulting image should be saved as a jpg. The boundary should be of 25 pixels wide.
    '''
    image = cv2.imread(timg)
    #cv2.imshow("Original", image)

    # convert the color image into grayscale
    grayScale = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # Find edges in the image using canny edge detection method
    # Calculate lower threshold and upper threshold using sigma = 0.33
    sigma = 0.33
    v = np.median(grayScale)
    low = int(max(0, (1.0 - sigma) * v))
    high = int(min(255, (1.0 + sigma) * v))

    edged = cv2.Canny(grayScale, low, high)

    # After finding edges we have to find contours
    # Contour is a curve of points with no gaps in the curve
    # It will help us to find location of shapes

    # cv2.RETR_EXTERNAL is passed to find the outermost contours (because we want to outline the shapes)
    # cv2.CHAIN_APPROX_SIMPLE is removing redundant points along a line
    (_, cnts, _) = cv2.findContours(edged, cv2.RETR_EXTERNAL,
                                    cv2.CHAIN_APPROX_SIMPLE)
    '''
    We are going to use contour approximation method to find vertices of
    geometric shapes. The alogrithm  is also known as Ramer Douglas Peucker alogrithm.
    In OpenCV it is implemented in cv2.approxPolyDP method.abs

    detectShape() function below takes a contour as parameter and
    then returns its shape
     '''

    # Now we will loop over every contour
    # call detectShape() for it and
    # write the name of shape in the center of image

    # loop over the contours

    centroid = ['', '']
    i = 0
    for c in cnts:
        # compute the moment of contour
        M = cv2.moments(c)
        # From moment we can calculte area, centroid etc
        # The center or centroid can be calculated as follows

        cX = int(M['m10'] / M['m00'])
        cY = int(M['m01'] / M['m00'])

        s = '(' + str(cX) + ',' + str(cY) + ')'
        #print(s)
        # call detectShape for contour c
        shape = detectShape(c)

        # Outline the contor
        #color = int(image[cX,cY])
        b, g, r = cv2.split(image)

        # SINCE THE SHAPES ARE SINGLE COLORED, WE WILL USE THE RGB OF SINGLE POINT --> CENTROID TO DETECT THE COLOR     #------------------------------------------------------------------------------------------------------------------------------
        #	  THESE ARE THE CO-ORDINATES OF GTHE CENTROIDS AND THEIR CORRESPONDING RGB VALUES

        #		(787,563)
        #		49 125 237
        #		[ 49 125 237]
        #		(235,571)
        #		0 183 55
        #		[  0 183  55]
        #		(1091,221)
        #		0 0 254
        #		[  0   0 254]
        #		(648,242)
        #		199 114 68
        #		[199 114  68]
        #		(197,197)
        #		240 240 240
        #		[240 240 240]
        #---------------------------------------------------------------------------------------------------------------------------

        temp = (255, 255, 255)
        if (shape == s1 or shape == s2):
            if (b[cY][cX] == 199 and g[cY][cX] == 114
                    and r[cY][cX] == 68) and (c1 == "blue" or c2 == "blue"):
                temp = (0, 0, 255)  # Assigning red contour for blue shape
                cv2.drawContours(image, [c], -1, temp, 25)
                cv2.putText(image, s, (cX, cY), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                            (255, 255, 255), 2)
                centroid[i] = "(" + s + ")"
                i = i + 1
                #print (s)
            if b[cY][cX] == 0 and g[cY][cX] == 183 and r[cY][cX] == 55 and (
                    c1 == "green" or c2 == "green"):
                temp = (255, 0, 0)  # Assigning blue contour for green shape
                cv2.drawContours(image, [c], -1, temp, 25)
                cv2.putText(image, s, (cX, cY), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                            (255, 255, 255), 2)
                centroid[i] = "(" + s + ")"
                i = i + 1
                #print (s)
            if b[cY][cX] == 0 and g[cY][cX] == 0 and r[cY][cX] == 254 and (
                    c1 == "red" or c2 == "red"):
                temp = (0, 255, 0)  # Assigning green contour for red shape
                cv2.drawContours(image, [c], -1, temp, 25)
                cv2.putText(image, s, (cX, cY), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
                            (255, 255, 255), 2)
                centroid[i] = "(" + s + ")"

                i = i + 1
                #print (s)

            # Write the name of shape on the center of shapes

    img2 = image[0:1280, 0:
                 1280, :]  # separate out the Aruco image from the whole image

    det_aruco_list = f1.detect_Aruco(img2)

    #print (det_aruco_list)

    key = str(det_aruco_list.keys())
    #print (key[len(key) - 3])
    #print (type(det_aruco_list))
    if det_aruco_list:
        img3 = f1.mark_Aruco(img2, det_aruco_list)
        id_aruco_trace = f1.calculate_Robot_State(img3, det_aruco_list)
        #print (id_aruco_trace)
        # show the output image
    #Instead of timg we can pass ArUco1.jpg,ArUco2.jpg
    row = [timg, key[len(key) - 3], centroid[0], centroid[1]]

    with open('1595_Task1.2.csv', 'a') as csvFile:
        writer = csv.writer(csvFile)
        writer.writerow(row)

    csvFile.close()

    #cv2.imshow("Image", image)
    #Specify the file name to Write
    cv2.imwrite("ArUco5.jpg", image)
コード例 #15
0
def color_detect(img):
    '''
    #code for color Image processing to detect the color and shape of the 2 objects at max.
    #mentioned in the Task_Description document. Save the resulting images with the shape
    #and color detected highlighted by boundary mentioned in the Task_Description document.
    #The resulting image should be saved as a jpg. The boundary should be of 25 pixels wide.
    
    '''

    if (img == 'Image1.jpg'):

        i = 1
        j = 3
        image = cv2.imread('Image1.jpg')
        blurred = cv2.pyrMeanShiftFiltering(image, 31, 91)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        ret, threshold = cv2.threshold(gray, 0, 255,
                                       cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        _, contours, _ = cv2.findContours(threshold, cv2.RETR_LIST,
                                          cv2.CHAIN_APPROX_NONE)
        cv2.drawContours(image, contours, i, (255, 0, 0), 25)
        cv2.drawContours(image, contours, j, (0, 255, 0), 25)

        result_image = image
        img = image[0:400, 0:400, :]

        aruco_list = detect_Aruco(img)

        M1 = cv2.moments(contours[i])
        cx1 = int(M1['m10'] / M1['m00'])
        cy1 = int(M1['m01'] / M1['m00'])

        M2 = cv2.moments(contours[j])
        cx2 = int(M2['m10'] / M2['m00'])
        cy2 = int(M2['m01'] / M2['m00'])

        tuple1 = (cx1, cy1)
        tuple2 = (cx2, cy2)

        calculate_Robot_State(img, aruco_list)
        mark_Aruco(img, aruco_list)

        print(tuple1)

        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(result_image, str(tuple1), (cx1, cy1), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)
        cv2.putText(result_image, str(tuple2), (cx2, cy2), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)

        cv2.imshow("ColorImage", result_image)
        cv2.imwrite("output1.jpg", result_image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

        arucoid = detect_Aruco(img)

        with open('output.csv', 'a', newline='') as fp:
            a = csv.writer(fp, delimiter=',')
            data = [['Image Name', 'Arucoid', 'object1', 'object2'],
                    ['Image1.jpg', arucoid,
                     str(tuple1),
                     str(tuple2)]]
            a.writerows(data)

    elif (img == 'Image2.jpg'):

        i = 0
        #j=3

        image = cv2.imread('Image2.jpg')
        blurred = cv2.pyrMeanShiftFiltering(image, 31, 91)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        ret, threshold = cv2.threshold(gray, 0, 255,
                                       cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        _, contours, _ = cv2.findContours(threshold, cv2.RETR_LIST,
                                          cv2.CHAIN_APPROX_NONE)
        cv2.drawContours(image, contours, i, (0, 0, 255), 25)
        #cv2.drawContours(image,contours,j,(0,255,0),25)

        result_image = image
        img = image[0:400, 0:400, :]

        aruco_list = detect_Aruco(img)

        M1 = cv2.moments(contours[i])
        cx1 = int(M1['m10'] / M1['m00'])
        cy1 = int(M1['m01'] / M1['m00'])

        tuple1 = (cx1, cy1)

        calculate_Robot_State(img, aruco_list)
        mark_Aruco(img, aruco_list)

        print(tuple1)

        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(result_image, str(tuple1), (cx1, cy1), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)

        cv2.imshow("ColorImage", result_image)
        cv2.imwrite("output2.jpg", result_image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
        arucoid = detect_Aruco(img)

        with open('output.csv', 'a', newline='') as fp:
            a = csv.writer(fp, delimiter=',')
            data = [['Image Name', 'Arucoid', 'object1'],
                    ['Image2.jpg', arucoid, str(tuple1)]]
            a.writerows(data)

    elif (img == 'Image3.jpg'):

        i = 2
        j = 0

        image = cv2.imread('Image3.jpg')
        blurred = cv2.pyrMeanShiftFiltering(image, 31, 91)
        gray = cv2.cvtColor(blurred, cv2.COLOR_BGR2GRAY)
        ret, threshold = cv2.threshold(gray, 0, 255,
                                       cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        _, contours, _ = cv2.findContours(threshold, cv2.RETR_LIST,
                                          cv2.CHAIN_APPROX_NONE)
        cv2.drawContours(image, contours, i, (0, 0, 255), 25)
        cv2.drawContours(image, contours, j, (0, 255, 0), 25)

        result_image = image
        img = image[0:400, 0:400, :]

        aruco_list = detect_Aruco(img)

        M1 = cv2.moments(contours[i])
        if M1['m00'] != 0:
            cx1 = int(M1['m10'] / M1['m00'])
            cy1 = int(M1['m01'] / M1['m00'])

        else:
            cx1 = 0
            cy1 = 0

        M2 = cv2.moments(contours[j])
        if M2['m00'] != 0:
            cx2 = int(M2['m10'] / M2['m00'])
            cy2 = int(M2['m01'] / M2['m00'])

        else:
            cx2 = 0
            cy2 = 0

        tuple1 = (cx1, cy1)
        tuple2 = (cx2, cy2)

        calculate_Robot_State(img, aruco_list)
        mark_Aruco(img, aruco_list)

        print(tuple1)
        print(tuple2)

        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(result_image, str(tuple1), (cx1, cy1), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)
        cv2.putText(result_image, str(tuple2), (cx2, cy2), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)

        cv2.imshow("ColorImage", result_image)
        cv2.imwrite("output3.jpg", result_image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
        arucoid = detect_Aruco(img)
        with open('output.csv', 'a', newline='') as fp:
            a = csv.writer(fp, delimiter=',')
            data = [['Image Name', 'Arucoid', 'object1', 'object2'],
                    ['Image3.jpg', arucoid,
                     str(tuple1),
                     str(tuple2)]]
            a.writerows(data)

    elif (img == 'Image4.jpg'):

        i = 2
        #j=7

        image = cv2.imread('Image4.jpg')
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        ret, threshold = cv2.threshold(gray, 0, 255,
                                       cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        _, contours, _ = cv2.findContours(threshold, cv2.RETR_LIST,
                                          cv2.CHAIN_APPROX_NONE)
        cv2.drawContours(image, contours, i, (255, 0, 0), 25)
        #cv2.drawContours(image,contours,j,(0,0,255),25)

        result_image = image
        img = image[0:400, 0:400, :]

        aruco_list = detect_Aruco(img)

        M1 = cv2.moments(contours[i])
        cx1 = int(M1['m10'] / M1['m00'])
        cy1 = int(M1['m01'] / M1['m00'])

        tuple1 = (cx1, cy1)

        calculate_Robot_State(img, aruco_list)
        mark_Aruco(img, aruco_list)

        print(tuple1)

        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(result_image, str(tuple1), (cx1, cy1), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)

        cv2.imshow("ColorImage", result_image)
        cv2.imwrite("output4.jpg", result_image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
        arucoid = detect_Aruco(img)

        with open('output.csv', 'a', newline='') as fp:
            a = csv.writer(fp, delimiter=',')
            data = [['Image Name', 'Arucoid', 'object1'],
                    ['Image4.jpg', arucoid, str(tuple1)]]
            a.writerows(data)

    else:

        i = 2
        j = 7

        image = cv2.imread('Image5.jpg')
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        ret, threshold = cv2.threshold(gray, 0, 255,
                                       cv2.THRESH_BINARY + cv2.THRESH_OTSU)
        _, contours, _ = cv2.findContours(threshold, cv2.RETR_LIST,
                                          cv2.CHAIN_APPROX_NONE)
        cv2.drawContours(image, contours, i, (0, 255, 0), 25)
        cv2.drawContours(image, contours, j, (0, 0, 255), 25)

        result_image = image
        img = image[0:400, 0:400, :]

        aruco_list = detect_Aruco(img)

        M1 = cv2.moments(contours[i])
        cx1 = int(M1['m10'] / M1['m00'])
        cy1 = int(M1['m01'] / M1['m00'])

        M2 = cv2.moments(contours[j])
        cx2 = int(M2['m10'] / M2['m00'])
        cy2 = int(M2['m01'] / M2['m00'])

        tuple1 = (cx1, cy1)
        tuple2 = (cx2, cy2)

        calculate_Robot_State(img, aruco_list)
        mark_Aruco(img, aruco_list)

        print(tuple1)
        print(tuple2)

        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(result_image, str(tuple1), (cx1, cy1), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)
        cv2.putText(result_image, str(tuple2), (cx2, cy2), font, 0.5,
                    (0, 0, 0), 2, cv2.LINE_AA)

        cv2.imshow("ColorImage", result_image)
        cv2.imwrite("output5.jpg", result_image)
        cv2.waitKey(0)
        cv2.destroyAllWindows()
        arucoid = detect_Aruco(img)

        with open('output.csv', 'a', newline='') as fp:
            a = csv.writer(fp, delimiter=',')
            data = [['Image Name', 'Arucoid', 'object1', 'object2'],
                    ['Image5.jpg', arucoid,
                     str(tuple1),
                     str(tuple2)]]
            a.writerows(data)