示例#1
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
示例#2
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
示例#3
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
示例#5
0
            angle_diff_yellow = np.arctan(slope_yellow) - np.pi / 2
        else:
            angle_diff_yellow = np.arctan(slope_yellow) + np.pi / 2
        print("slope yellow = ", slope_yellow)
        angle_diffs.append(angle_diff_yellow)

    if not line_whites == []:
        slope_whites = [line[0] for line in line_whites]
        slope_white = np.average(slope_whites, axis=0)
        if slope_white > 0:
            angle_diff_white = np.arctan(slope_white) - np.pi / 2
        else:
            angle_diff_white = np.arctan(slope_white) + np.pi / 2
        print("slope white = ", slope_white)
        angle_diffs.append(angle_diff_white)

    angle_diff = np.average(angle_diffs)
    print("angle diff = ", angle_diff)
    print("controller = ",
          _control_center((np.sin(angle_diff), np.cos(angle_diff))))


if __name__ == "__main__":
    for filename in sys.argv[1:]:
        img = cv2.imread(filename)
        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)
        control(line_yellows, line_whites)