From 04c52c6c1a91716f4c3ca7d8a2f897a770505fe9 Mon Sep 17 00:00:00 2001 From: rykeenan Date: Sun, 4 Jun 2017 17:05:10 -0700 Subject: [PATCH] update rover_coords() --- code/Rover_Project_Test_Notebook.ipynb | 17 +++++++++-------- code/perception.py | 6 +++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/code/Rover_Project_Test_Notebook.ipynb b/code/Rover_Project_Test_Notebook.ipynb index 67207cb4d6..de3bb2546d 100644 --- a/code/Rover_Project_Test_Notebook.ipynb +++ b/code/Rover_Project_Test_Notebook.ipynb @@ -5795,13 +5795,14 @@ { "cell_type": "code", "source": [ + "# Define a function to convert from image coords to rover coords\n", "def rover_coords(binary_img):\n", " # Identify nonzero pixels\n", " ypos, xpos = binary_img.nonzero()\n", " # Calculate pixel positions with reference to the rover position being at the \n", " # center bottom of the image. \n", - " x_pixel = np.absolute(ypos - binary_img.shape[0]).astype(np.float)\n", - " y_pixel = -(xpos - binary_img.shape[0]).astype(np.float)\n", + " x_pixel = -(ypos - binary_img.shape[0]).astype(np.float)\n", + " y_pixel = -(xpos - binary_img.shape[1]/2 ).astype(np.float)\n", " return x_pixel, y_pixel\n", "\n", "# Define a function to convert to radial coords in rover space\n", @@ -9261,16 +9262,16 @@ "display_name": "Python 3" }, "language_info": { - "pygments_lexer": "ipython3", + "nbconvert_exporter": "python", "version": "3.5.2", + "file_extension": ".py", "name": "python", - "mimetype": "text/x-python", + "pygments_lexer": "ipython3", "codemirror_mode": { - "version": 3, - "name": "ipython" + "name": "ipython", + "version": 3 }, - "file_extension": ".py", - "nbconvert_exporter": "python" + "mimetype": "text/x-python" } }, "nbformat": 4, diff --git a/code/perception.py b/code/perception.py index ed04437804..acf479ddab 100644 --- a/code/perception.py +++ b/code/perception.py @@ -17,14 +17,14 @@ def color_thresh(img, rgb_thresh=(160, 160, 160)): # Return the binary image return color_select -# Define a function to convert to rover-centric coordinates +# Define a function to convert from image coords to rover coords def rover_coords(binary_img): # Identify nonzero pixels ypos, xpos = binary_img.nonzero() # Calculate pixel positions with reference to the rover position being at the # center bottom of the image. - x_pixel = np.absolute(ypos - binary_img.shape[0]).astype(np.float) - y_pixel = -(xpos - binary_img.shape[0]).astype(np.float) + x_pixel = -(ypos - binary_img.shape[0]).astype(np.float) + y_pixel = -(xpos - binary_img.shape[1]/2 ).astype(np.float) return x_pixel, y_pixel