1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Python3 Opencv template matching with Contours on jetson nano [closed]

Discussão em 'Python' iniciado por Stack, Outubro 1, 2024 às 00:02.

  1. Stack

    Stack Membro Participativo

    I have a problem to get result from OpenCV template matching with Contours on Jetson Nano En715. The below code working perfect on PC (windows and Linux) system without any delay or lag, but when I run it on Jetson Nano En715 with USB camera C270 Logitech (this camera same as camera I use on pc). I can not matching template. No error, just the template and image are not match.

    Dose anyone can help me what is the problem? maybe from my code or maybe Jetson Nano En715 so weak for that and has lag.

    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    from math import copysign, log10
    MatchImage = False
    vc = cv2.VideoCapture(0)
    template = cv2.imread('template.jpg')
    template_img = template
    plt.axis('off')
    plt.imshow(template)
    plt.title('OUR TEMPLATE')
    plt.show()
    template = cv2.cvtColor(template,cv2.COLOR_BGR2GRAY)
    _, target = vc.read()
    img_copy=target.copy()
    target_gray = cv2.cvtColor(target,cv2.COLOR_BGR2GRAY)
    plt.axis('off')
    plt.imshow(target)
    plt.title('OUR TARGET')
    plt.show()
    ret,thresh1 = cv2.threshold(template,127,255,0)
    ret,thresh2 = cv2.threshold(target_gray,127,255,0)
    contours,hierarchy = cv2.findContours(thresh1,cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
    if hierarchy[0][0][3] == -1 :
    cv2.drawContours(template_img,contours,-1,(0,255,0),3)
    else:
    cv2.drawContours(template_img,contours,-1,(0,0,255),3)
    plt.axis('off')
    plt.imshow(template_img)
    plt.title('Identifying the Contours')
    plt.show()
    sorted_contours = sorted(contours, key=cv2.contourArea, reverse=True)
    template_contour = contours[1]
    contours,hierarchy = cv2.findContours(thresh2,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
    for c in contours:
    match = cv2.matchShapes(template_contour,c,3,0.0)
    print(match)
    if match < 0.15:
    closest_contour = c
    area = cv2.contourArea(c)
    printtext = 'data print: ' + str(area)
    print (printtext)
    if (match < 0.01):
    cv2.drawContours(target,[closest_contour],-1,(255,0,0),3)
    c = max([closest_contour], key = cv2.contourArea)
    x,y,w,h = cv2.boundingRect(c)
    cv2.rectangle(target, (x,y), (x+w,y+h), (0,255,0), 5)
    print ("Match")
    MatchImage = True
    plt.title("Original Image with a bounding box")
    plt.imshow(target)
    plt.show()
    if MatchImage == False:
    print("not match")
    plt.title("Original Image with a bounding box")
    plt.imshow(target)
    plt.show()
    if MatchImage == True:
    plt.title("Original Image with a bounding box")
    plt.imshow(target)
    plt.show()

    Continue reading...

Compartilhe esta Página