0

i am trying to make a racing robot , which will stop at Finish Line (of Magenta Color) . i hv tried to do so by converting the image to hsv and then masking it but it is not working as expected . Your help would be highly appretiated .

The code which i had written is :

import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(True):
    ret,frame=cap.read()
    blurredimg = cv2.GaussianBlur(frame,(11,11),0)
    imghsv=cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
    lowermagenta= np.array([0,50,50])
    uppermagenta= np.array([10,255,255])
    mask=cv2.inRange(imghsv,lowermagenta,uppermagenta)
    outputimg=frame.copy()
    outputimg[np.where(mask==0)]=0
    grayedimg = cv2.cvtColor(outputimg , cv2.COLOR_BGR2GRAY)
    cannyimg=cv2.Canny(grayedimg,75,150)
    ret,thresh = cv2.threshold(cannyimg,127,255,0)
    image , contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    finallimg= cv2.drawContours(frame,contours, -1,(0,255,0),35)
    cv2.imshow('hyg' , finallimg)
    cv2.imshow('hyg1' , cannyimg)
    for x in range (0,480):
        red,green,blue=finallimg[x,150]
        if red==0 and green==255 and blue==0 :
            print('magenta line found')
            break
  • Post an image of what are you working on.. – lucians May 05 '18 at 23:10
  • [Choosing the correct upper and lower HSV boundaries for color detection with`cv::inRange` (OpenCV)](https://stackoverflow.com/questions/10948589/choosing-the-correct-upper-and-lower-hsv-boundaries-for-color-detection-withcv/48367205#48367205) – Kinght 金 May 06 '18 at 04:29
  • Possible duplicate of [Choosing the correct upper and lower HSV boundaries for color detection with\`cv::inRange\` (OpenCV)](https://stackoverflow.com/questions/10948589/choosing-the-correct-upper-and-lower-hsv-boundaries-for-color-detection-withcv) – Jeru Luke May 06 '18 at 05:38

0 Answers0