Beispiel #1
0
def get_contour_from_image(img):
    line_yellows = get_range(
        img, np.array([10, 100, 180], np.uint8),
        np.array([60, 255, 255], np.uint8), cv2.COLOR_BGR2HSV
    )  # u: 10/110/200 ; 40/255/255   f: 20/110/200 ; 40/255/255
    line_whites = get_range(
        img, np.array([65, 150, 30], np.uint8),
        np.array([255, 255, 180], np.uint8), cv2.COLOR_BGR2HLS
    )  # u: 80/150/30 ; 255/255/130   f: 80/150/30 ; 255/255/150
    line_reds = get_range(img, np.array([150, 0, 0], np.uint8),
                          np.array([255, 255, 255], np.uint8),
                          cv2.COLOR_BGR2HLS)
    img_gray = cv2.cvtColor(
        img, cv2.COLOR_BGR2GRAY)  # convert the color image to gray image
    contours = get_gray_countour(img_gray)
    contour_dump("img3/contours_full" + str(int(time.time() * 10)) + ".jpg",
                 contours, img)
    _, contours = remove_contour(line_yellows, contours, 1)
    if len(contours) == 0: return None
    # _, contours = remove_contour( line_whites, contours, -1 ) # u: ##   f: ~~
    if len(contours) == 0: return None
    contour_left = contour_largest(contours)  # u: largest   f: leftest
    contour_dump(
        "img/contours_extracted" + str(int(time.time() * 10)) + ".jpg",
        contour_left, img)
    return contour_left
Beispiel #2
0
def get_contour_from_image( img ):
	line_yellows = get_yellow( img )
	line_whites  = get_range( img, np.array([0,160,0], np.uint8), np.array([255,255,255], np.uint8), cv2.COLOR_BGR2HLS)
	line_reds    = get_range( img, np.array([150,0,0], np.uint8), np.array([255,255,255], np.uint8), cv2.COLOR_BGR2HLS)
	img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # convert the color image to gray image
	contours = get_gray_countour(img_gray)
	contour_dump( "img/contours_full" + str(int(time.time()*10)) + ".jpg", contours, img)
	_, contours = remove_contour( line_yellows, contours, 1 )
	if len(contours) == 0: return None
	_, contours = remove_contour( line_whites, contours, -1 )
	if len(contours) == 0: return None
	contour_left = contour_leftest(contours)
	contour_dump( "img/contours_extracted" + str(int(time.time()*10)) + ".jpg", contour_left, img)
	return contour_left
Beispiel #3
0
def get_contour_from_image(img):
    line_yellows = get_yellow(img)
    line_whites = get_range(img, np.array([0, 100, 0], np.uint8),
                            np.array([255, 255, 255], np.uint8),
                            cv2.COLOR_BGR2HLS)
    line_reds = get_range(img, np.array([150, 0, 0], np.uint8),
                          np.array([255, 255, 255], np.uint8),
                          cv2.COLOR_BGR2HLS)
    img_gray = cv2.cvtColor(
        img, cv2.COLOR_BGR2GRAY)  # convert the color image to gray image
    contours = get_gray_countour(img_gray)
    _, contours = remove_contour(line_yellows, contours, 1)
    _, contours = remove_contour(line_whites, contours, -1)
    contour_left = contour_leftest(contours)
    return contour_left
Beispiel #4
0
def get_contour_from_image(img):
    line_yellows = get_yellow(img)
    line_whites = get_white(img)
    line_reds = get_red(img)
    img_gray = cv2.cvtColor(
        img, cv2.COLOR_BGR2GRAY)  # convert the color image to gray image
    contours = get_gray_countour(img_gray)
    contour_dump("img/contours_full" + str(int(time.time() * 10)) + ".jpg",
                 contours, img)
    _, contours = remove_contour(line_yellows, contours, 1)
    if len(contours) == 0: return None
    # _, contours = remove_contour( line_whites, contours, -1 )
    # if len(contours) == 0: return None
    contour_left = contour_largest(contours)
    contour_dump(
        "img/contours_extracted" + str(int(time.time() * 10)) + ".jpg",
        contour_left, img)
    return contour_left, len(line_reds)
def get_contour_from_image( img ):
	line_yellows = get_yellow( img )
	# line_whites  = get_white( img )
	line_reds    = get_red( img )

	global redline_cnt

	if not line_reds:
		
		redline_cnt = 0
		print("no red line")

	else:
		redline_cnt += 1
		# cmd = "redline \n"
		# s.write(cmd.encode())
		print("red lines:{0}".format(redline_cnt))

	if redline_cnt >= 20:

		cmd = "/ServoStop/run \n"

		s.write(cmd.encode())

		return None

	img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # convert the color image to gray image
	contours = get_gray_countour(img_gray)

	# contour_dump( "img/contours_full" + str(int(time.time()*10)) + ".jpg", contours, img)

	_, contours = remove_contour( line_yellows, contours, 1 )
	if len(contours) == 0: return None

	# _, contours = remove_contour( line_whites, contours, -1 )
	# if len(contours) == 0: return None

	contour_large = contour_largest(contours)
	# contour_dump( "img/contours_extracted" + str(int(time.time()*10)) + ".jpg", contour_large, img)
	contour_dump( "img/contours_extracted.jpg", contour_large, img)
	return contour_large
Beispiel #6
0
                         3)
                ang = np.arctan2(
                    np.shape(img)[1] / 2 - detect_pt[0],
                    np.shape(img)[0] - detect_pt[1])
                accept_pts.append(ang)
        if len(accept_pts): return accept_pts


if __name__ == "__main__":
    global filename, f, start_time
    filename = "test"

    img = cv2.imread(sys.argv[1])
    print("img size = ", np.shape(img))
    line_yellows = get_yellow(img)
    line_whites = get_range(img, np.array([0, 100, 0], np.uint8),
                            np.array([255, 255, 255], np.uint8),
                            cv2.COLOR_BGR2HLS)
    line_reds = get_range(img, np.array([150, 0, 0], np.uint8),
                          np.array([255, 255, 255], np.uint8),
                          cv2.COLOR_BGR2HLS)
    img_gray = cv2.cvtColor(
        img, cv2.COLOR_BGR2GRAY)  # convert the color image to gray image
    contours = get_gray_countour(img_gray)
    _, contours = remove_contour(line_yellows, contours, 1)
    _, contours = remove_contour(line_whites, contours, -1)
    contour_left = contour_leftest(contours)
    accept_pts = draw_line_in_contours(img, contour_left)
    speed, turn = control_arc(accept_pts)
    print("speed, turn = ", speed, turn)