Difference between revisions of "OpenCV4"
(68 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
=== Process === | === Process === | ||
==== Install OpenCV==== | ==== Install OpenCV==== | ||
− | Follow these instruction<ref>Open CV instruction:[https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ Link]</ref> to install OpenCV onto your Raspberry Pi using the terminal. | + | Follow these [https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ instruction]<ref>Open CV instruction:[https://www.pyimagesearch.com/2018/09/26/install-opencv-4-on-your-raspberry-pi/ Link]</ref> to install OpenCV onto your Raspberry Pi using the terminal. |
− | *Important note: | + | *'''Important note''': Don't do <code>make-j4</code> since the raspberry pi may freeze so it best to just do <code>make</code> or <code>make-j1</code>. |
Line 17: | Line 17: | ||
==== Capturing image==== | ==== Capturing image==== | ||
− | Following these step to set up your camera<ref>Setting up camera:[https://www.dexterindustries.com/howto/installing-the-raspberry-pi-camera/ Link]</ref> | + | [[File:cam.PNG|400px|thumb|left|Taking picture code]] |
+ | Following these step to [https://www.dexterindustries.com/howto/installing-the-raspberry-pi-camera/ set up your camera]<ref>Setting up camera:[https://www.dexterindustries.com/howto/installing-the-raspberry-pi-camera/ Link]</ref> | ||
− | + | Note: Ignoring GoPiGo installation. | |
+ | |||
+ | |||
+ | Once the camera is set up, it is ready to take pictures. In order to capture image, follow these [https://medium.com/@petehouston/capture-images-from-raspberry-pi-camera-module-using-picamera-505e9788d609 instruction] <ref>Capturing Image:[https://medium.com/@petehouston/capture-images-from-raspberry-pi-camera-module-using-picamera-505e9788d609 Link]</ref> | ||
− | |||
− | |||
− | |||
− | |||
Note: | Note: | ||
− | *Use <code>sleep</code> (measured in seconds) to create a delay between the preview: <code>time.sleep(seconds)</code> | + | **Use <code>sleep</code> (measured in seconds) to create a delay between the preview: <code>time.sleep(seconds)</code> |
− | *Another way to enable your camera is: go to the terminal → type in <code>sudo raspi-config</code> → select <code>Enable Camera</code> → press Enter → select <code>Finish</code> → reboot and log back on to the Raspberry Pi. | + | **Another way to enable your camera is: go to the terminal → type in <code>sudo raspi-config</code> → select <code>Enable Camera</code> → press Enter → select <code>Finish</code> → reboot and log back on to the Raspberry Pi. |
==== Edge Detector==== | ==== Edge Detector==== | ||
− | + | [[File:Edges.PNG|350px|thumb|right|Sample Edge Detector]] | |
Once you have a picture, you may want to use edge detection to detect the chessboard region of interest. | Once you have a picture, you may want to use edge detection to detect the chessboard region of interest. | ||
− | Follow these instruction for Canny edge detection<ref>Canny edge detection:[https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_canny/py_canny.html Link]</ref> | + | Follow these instruction for [https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_canny/py_canny.html Canny edge detection]<ref>Canny edge detection:[https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_canny/py_canny.html Link]</ref> |
* Note: Scroll down to the Explanation section. | * Note: Scroll down to the Explanation section. | ||
+ | |||
+ | Follow this [https://docs.opencv.org/3.4.0/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de/ Link]<ref name="a">Parameter:[https://docs.opencv.org/3.4.0/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de/ Link]</ref>if you want to see its parameters.(search for Canny Edge) | ||
In order to use build-in function in Open CV: remember to <code>import</code> cv2. In the instruction, the <code>import</code> cv2 <code>as</code>cv means that you can now type in cv instead of cv2 when using build-in function. | In order to use build-in function in Open CV: remember to <code>import</code> cv2. In the instruction, the <code>import</code> cv2 <code>as</code>cv means that you can now type in cv instead of cv2 when using build-in function. | ||
− | |||
− | |||
− | |||
Ex: | Ex: | ||
Line 58: | Line 57: | ||
==== Houghline Transformation==== | ==== Houghline Transformation==== | ||
− | Using the Canny Edge detection to find the region of interest(edges of the image) prior to the Houghline Transformation,one can now use the Hougline Tranformation: | + | [[File:lines.PNG|550px|thumb|left|Sample Houghline Transformation]] |
+ | Using the Canny Edge detection to find the region of interest(edges of the image) prior to the Houghline Transformation,one can now ready to use the Hougline Tranformation. | ||
+ | |||
+ | |||
+ | The process should be: capturing an image→Canny Edge Detection→Houghline Transformation. | ||
+ | |||
+ | |||
+ | Follow the following instruction for [https://docs.opencv.org/3.4.0/d9/db0/tutorial_hough_lines.html Houghline Transformation].<ref>Houghline Transformation:[https://docs.opencv.org/3.4.0/d9/db0/tutorial_hough_lines.html Link]</ref> | ||
+ | |||
+ | Follow this [https://docs.opencv.org/3.4.0/dd/d1a/group__imgproc__feature.html#ga04723e007ed888ddf11d9ba04e2232de/ Link]<ref name="a" />if you want to see its parameters.(search for Hough Line) | ||
+ | |||
+ | |||
+ | Example: | ||
+ | |||
<code>lines = cv.HoughLines(dst, 1, np.pi / 180, 150, None, 0, 0)</code> | <code>lines = cv.HoughLines(dst, 1, np.pi / 180, 150, None, 0, 0)</code> | ||
+ | |||
+ | === Sample Projects === | ||
+ | |||
+ | *ESE205-CVChess/board_Recognition.py <ref> ESE205-CVChess/board_Recognition.py :[https://github.com/rjgoodloe/ESE205-CVChess/blob/master/board_Recognition.py Links]</ref> | ||
+ | |||
+ | *DE3-ROB1-CHESS/perception.mainDetect<ref> DE3-ROB1-CHESS/perception.mainDetect: [https://de3-rob1-chess.readthedocs.io/en/latest/_modules/perception/mainDetect.html#Perception.makeBoard/ Links]</ref> | ||
=== Authors === | === Authors === |
Latest revision as of 18:52, 12 December 2018
Contents
Overview
This is a tutorial on how to install OpenCV4 and use camera module.
Materials/Prerequisites
- Raspberry Pi
- Raspberry Pi Camera
Process
Install OpenCV
Follow these instruction[1] to install OpenCV onto your Raspberry Pi using the terminal.
- Important note: Don't do
make-j4
since the raspberry pi may freeze so it best to just domake
ormake-j1
.
After you have successfully installed OpenCV, you will be able to use import cv2
. If you do it on the terminal, you want to put in these code source ~/.profile
and then workon cv
.
Capturing image
Following these step to set up your camera[2]
Note: Ignoring GoPiGo installation.
Once the camera is set up, it is ready to take pictures. In order to capture image, follow these instruction [3]
Note:
- Use
sleep
(measured in seconds) to create a delay between the preview:time.sleep(seconds)
- Use
- Another way to enable your camera is: go to the terminal → type in
sudo raspi-config
→ selectEnable Camera
→ press Enter → selectFinish
→ reboot and log back on to the Raspberry Pi.
- Another way to enable your camera is: go to the terminal → type in
Edge Detector
Once you have a picture, you may want to use edge detection to detect the chessboard region of interest.
Follow these instruction for Canny edge detection[4]
- Note: Scroll down to the Explanation section.
Follow this Link[5]if you want to see its parameters.(search for Canny Edge)
In order to use build-in function in Open CV: remember to import
cv2. In the instruction, the import
cv2 as
cv means that you can now type in cv instead of cv2 when using build-in function.
Ex: To load image:
- src =
cv.imread
(filename, cv.IMREAD_GRAYSCALE)
Then use:
- dst =
cv.Canny
(src, 50, 200, None, 3)
Houghline Transformation
Using the Canny Edge detection to find the region of interest(edges of the image) prior to the Houghline Transformation,one can now ready to use the Hougline Tranformation.
The process should be: capturing an image→Canny Edge Detection→Houghline Transformation.
Follow the following instruction for Houghline Transformation.[6]
Follow this Link[5]if you want to see its parameters.(search for Hough Line)
Example:
lines = cv.HoughLines(dst, 1, np.pi / 180, 150, None, 0, 0)
Sample Projects
- ESE205-CVChess/board_Recognition.py [7]
- DE3-ROB1-CHESS/perception.mainDetect[8]
Authors
- Nhut Dang
- Robert Goodloe
- Ethan Shry(TA)
Fall 2018