Robotics 1 U2 (Sensors and Vision) S5 (Camera Coordinates) P1 (Pixel to Centimeter Conversion)

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 พ.ย. 2024

ความคิดเห็น • 15

  • @adamakoumare4264
    @adamakoumare4264 ปีที่แล้ว

    Merci beaucoup, vos vidéos vont beaucoup m'aider

  • @mathmath64
    @mathmath64 3 ปีที่แล้ว

    Nice work !
    Thank you for all the explanation Angela .
    Can you tell me what's the webcam you are using ? ( it's mark or label )
    and where can i find it online ?
    Thankx again .

  • @hedundar
    @hedundar 2 ปีที่แล้ว

    hi ,firstly thank you this great video. i have one question. i completely write codes in video but something went wrong. my code give just one coordinat to me. not real time. what do you think my mistake? if you answer i will be very happy. thank you for your time

  • @seeking9145
    @seeking9145 4 ปีที่แล้ว

    Do you have a link of the previous video of which you talked aboit?

  • @vinhlehoang2427
    @vinhlehoang2427 3 ปีที่แล้ว

    Please tell me why I have to take 11.3/640 and what is 640 ?. Thanks!

    • @asodemann3
      @asodemann3  3 ปีที่แล้ว

      640 is the width of the view in pixels, and 11.3 is the width in centimeters. So, this value gives you a unit conversion number in cm per pixel.

    • @vinhlehoang2427
      @vinhlehoang2427 3 ปีที่แล้ว

      ​@@asodemann3
      cm_to_pixel=27.7/700.0
      a=0
      b=0
      def init_serial():
      COMNUM = 1
      global ser
      ser = serial.Serial()
      ser.baudrate = 9600
      ser.port = "COM2" # cong com ket noi UART voi C#
      ser.timeout = 10
      ser.open()
      init_serial()
      # construct the argument parse and parse the arguments
      ap = argparse.ArgumentParser()
      ap.add_argument("-v", "--video",
      help="path to the (optional) video file")
      ap.add_argument("-b", "--buffer", type=int, default=64,
      help="max buffer size")
      args = vars(ap.parse_args())
      # xác định ranh giới phía dưới và phía trên của các màu trong không gian màu HSV
      lower = {'red': (0, 75, 140), 'green': (40, 70, 80), 'blue': (97, 100, 117), 'yellow': (
      25, 70, 120)} # assign new item lower['blue'] = (93, 10, 0),'blue':(97, 100, 117),'green':(40, 70, 80)
      upper = {'red': (8, 255, 255), 'green': (70, 255, 255), 'blue': (117, 255, 255),
      'yellow': (60, 255, 255)} # 'green':(65,255,255)
      # xác định màu tiêu chuẩn cho vòng tròn xung quanh đối tượng
      colors = {'red': (0, 0, 255), 'green': (0, 255, 0), 'blue': (255, 0, 0), 'yellow': (0, 255, 217)}
      # pts = deque(maxlen=args["buffer"])
      # if a video path was not supplied, grab the reference
      # to the webcam
      if not args.get("video", False):
      camera = cv2.VideoCapture(0)
      # otherwise, grab a reference to the video file
      else:
      camera = cv2.VideoCapture(args["video"])
      # keep looping
      while True:
      # grab the current frame
      (grabbed, frame) = camera.read()
      # if we are viewing a video and we did not grab a frame,
      # then we have reached the end of the video
      if args.get("video") and not grabbed:
      break
      # resize the frame, blur it, and convert it to the HSV
      # color space
      frame = imutils.resize(frame, width=700) # thay đổi kích thước khung 700 pixel
      blurred = cv2.GaussianBlur(frame, (11, 11), 0) #làm mờ khung để giảm nhiễu tần số cao và cho phép chúng tôi tập trung vào các đối tượng bên trong khung hình
      hsv = cv2.cvtColor(blurred, cv2.COLOR_BGR2HSV) # chuyển đổi khung hình thành không gian HSV
      # for each color in dictionary check object in frame
      for key, value in upper.items():
      # construct a mask for the color from dictionary`1, then perform
      # a series of dilations and erosions to remove any small
      # blobs left in the mask
      kernel = np.ones((9, 9), np.uint8)
      mask = cv2.inRange(hsv, lower[key], upper[key]) #xử lý định vị thực tế của màu dc tìm thấy trong khung hình bằng cách gọi đến cv2.inRange
      #cung cấp các ranh giới màu HSV dưới cho các màu, tiếp theo là các ranh giới HSV trên. Đầu ra của cv2.inRange là một mặt nạ nhị phân
      mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel) # 78 79 loại bỏ bất kỳ đốm màu nhỏ nào có thể còn sót lại trên mặt nạ.
      mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
      # find contours in the mask and initialize the current
      # (x, y) center of the ball
      cnts = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL,
      cv2.CHAIN_APPROX_SIMPLE)[-2] # tính toán đường viền của các đối tượng trong hình ảnh
      center = None # khởi động tọa độ tâm
      # chỉ tiếp tục nếu ít nhất một đường bao được tìm thấy
      if len(cnts) > 0:
      c = max(cnts, key=cv2.contourArea) # tìm đường bao lớn nhất
      ((x, y), radius) = cv2.minEnclosingCircle(c) #tính vòng tròn nhỏ nhất bao quanh của vòng màu
      areal = cv2.contourArea(c) # dien tich (khu vuc) duong vien
      cv2.drawContours(frame, [c], -1, colors[key], 3)
      M = cv2.moments(c)
      cx = int(M["m10"] / M["m00"])
      cy = int(M["m01"] / M["m00"]) # 93 94 95 xác định tọa độ tâm
      # chỉ tiến hành nếu bán kính đáp ứng kích thước tối thiểu. Sửa giá trị này cho kích thước đối tượng của bạn
      cv2.circle(frame, (cx, cy), 7, (255, 255, 255), -1) # tâm
      cv2.putText(frame, key, (cx - 20, cy - 20), cv2.FONT_HERSHEY_SIMPLEX, 2.5, (255, 255, 255), 3) # vòn bao quanh vật
      a=round(cx*(cm_to_pixel),2) # chuyển x từ pixel sang cm
      b=round(cy*(cm_to_pixel),2) # chuyển y từ pixel sang cm
      x = str(a)
      y = str(b)
      print("center: ", x ,y)

  • @amarmkulkarni
    @amarmkulkarni 4 ปีที่แล้ว

    sir, plese provide codes in the description

  • @nikunjanghan7101
    @nikunjanghan7101 3 ปีที่แล้ว

    I’m doing this thing for image and I’m facing some issues can you please help me

    • @asodemann3
      @asodemann3  3 ปีที่แล้ว +1

      Possibly... Go ahead and ask, and maybe I or someone else can help

    • @nikunjanghan7101
      @nikunjanghan7101 3 ปีที่แล้ว

      @@asodemann3 thank you
      Actually i want a particular point’s (x,y) coordinates in terms of centimetres
      But i get whole image coordinates in all the points which i have selected

    • @nikunjanghan7101
      @nikunjanghan7101 3 ปีที่แล้ว

      import cv2
      import numpy as np
      image = cv2.imread('main.png')
      def click_event(event, x, y, flag, param):
      if event == cv2.EVENT_LBUTTONDOWN:
      font = cv2.FONT_HERSHEY_SIMPLEX
      strXY = str(X_Location) + ', ' + str(Y_Location)
      cv2.putText(image, strXY, (x, y), font, 0.5, (0, 0, 255), 1)
      print(strXY)
      cv2.imshow('image', image)
      #image = cv2.resize(image, (640, 480))
      gray_image1 = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
      gray_image2 = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
      cm_to_pixel = 16.93/640
      Difference = np.absolute(np.matrix(np.int16(gray_image1)))
      Difference[Difference > 300] = 300
      Difference = np.uint8(Difference)
      BW = Difference
      BW[BW 100] = 1
      column_sums = np.matrix(np.sum(BW, 0))
      column_numbers = np.matrix(np.arange(781))
      column_multi = np.multiply(column_sums, column_numbers)
      total = np.sum(column_multi)
      total_total = np.sum(np.sum(BW))
      column_location = total/total_total
      X_Location = column_location*cm_to_pixel
      row_sums = np.matrix(np.sum(BW, 1))
      row_sums = row_sums.transpose()
      row_numbers = np.matrix(np.arange(721))
      row_multi = np.multiply(row_sums, row_numbers)
      total = np.sum(row_multi)
      total_total = np.sum(np.sum(BW))
      row_location = total / total_total
      Y_Location = row_location*cm_to_pixel
      print(X_Location, Y_Location)
      cv2.imshow('image', image)
      cv2.setMouseCallback('image', click_event)
      cv2.waitKey(0)
      can you please tell me my mistakes in this code

    • @asodemann3
      @asodemann3  3 ปีที่แล้ว

      @@nikunjanghan7101 I see that your image is resized to 640x480 and that 640 is what you use in your cm to pixel conversion ratio, but your arange vectors are both more than 700. I think those arange things should match the image dimensions - 640 for the columns and 480 for the rows.
      That's my best first guess!

    • @nikunjanghan7101
      @nikunjanghan7101 3 ปีที่แล้ว +1

      @@asodemann3 thank you