Robotics StackExchange | Archived questions

BGR2HSV NOT WORKING

I have been working on a code where the camera has to detect the color blue, and it works but instead of the image coming out well, what is orange comes out blue and what is blue comes out orange. this is my code:

 video=cv2.VideoCapture(1)
        ret, frame = video.read()
        if ret == True:
            frameHSV = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
            mask = cv2.inRange(frameHSV,azulBajo,azulAlto)
            contornos, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
            for c in contornos:
                area = cv2.contourArea(c)
                if area > 3000:
                    M = cv2.moments(c)
                    if (M["m00"]==0): M["m00"]=1
                    x = int(M["m10"]/M["m00"])
                    y = int(M['m01']/M['m00'])
                    cv2.circle(frame, (x,y), 7, (0,255,0), -1)
                    font = cv2.FONT_HERSHEY_SIMPLEX
                    cv2.putText(frame, '{},{}'.format(x,y),(x+10,y), font, 0.75,(0,255,0),1,cv2.LINE_AA)
                    nuevoContorno = cv2.convexHull(c)
                    cv2.drawContours(frame, [nuevoContorno], 0, (255,0,0), 3)

Asked by AGC on 2023-02-14 13:24:18 UTC

Comments

I'm sorry, but this reads like a purely OpenCV question.

While we definitely use OpenCV with ROS, ROS Answers is not the place to ask questions about OpenCV.

Please repost your question at a more suitable venue, such as forum.opencv.org or robotics stack exchange.

Asked by gvdhoorn on 2023-02-15 02:41:38 UTC

Answers