Find The Center Of A White Line In An Image Using OpenCV · GitHub
Có thể bạn quan tâm
Skip to content All gists Back to GitHub Sign in Sign up Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.
Instantly share code, notes, and snippets.
araffin/color_mask.py Created October 6, 2017 15:56 Show Gist options- Download ZIP
- Star ( ) You must be signed in to star a gist
- Fork ( ) You must be signed in to fork a gist
- Embed Clone this repository at <script src="https://gist.github.com/araffin/6728aec43b2ed6b1b07738f4c3a42cf5.js"></script>
- Save araffin/6728aec43b2ed6b1b07738f4c3a42cf5 to your computer and use it in GitHub Desktop.
from __future__ import division |
import cv2 |
import numpy as np |
# Input Image |
image = cv2.imread("my_image.jpg") |
# Convert to HSV color space |
hsv = cv2.cvtColor(image, cv2.COLOR_RGB2HSV) |
# Define range of white color in HSV |
lower_white = np.array([0, 0, 212]) |
upper_white = np.array([131, 255, 255]) |
# Threshold the HSV image |
mask = cv2.inRange(hsv, lower_white, upper_white) |
# Remove noise |
kernel_erode = np.ones((4,4), np.uint8) |
eroded_mask = cv2.erode(mask, kernel_erode, iterations=1) |
kernel_dilate = np.ones((6,6),np.uint8) |
dilated_mask = cv2.dilate(eroded_mask, kernel_dilate, iterations=1) |
# Find the different contours |
im2, contours, hierarchy = cv2.findContours(dilated_mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) |
# Sort by area (keep only the biggest one) |
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:1] |
if len(contours) > 0: |
M = cv2.moments(contours[0]) |
# Centroid |
cx = int(M['m10']/M['m00']) |
cy = int(M['m01']/M['m00']) |
print("Centroid of the biggest area: ({}, {})".format(cx, cy)) |
else: |
print("No Centroid Found") |
Từ khóa » Hsv Color Space White
-
Tracking White Color Using Python Opencv - Stack Overflow
-
HSL And HSV - Wikipedia
-
HSV White Color Range In JS - OpenCV Q&A Forum
-
Image Segmentation Using Color Spaces In OpenCV + Python
-
Tracking White Color Using Python Opencv - Win Mundo
-
HSV Color Wheel Figure 6 Illustrates How Hue, Saturation, And Value ...
-
The Three Dimensional HSV Color Space. Hue (H) Captures The ...
-
OpenCV Color Spaces ( tColor ) - PyImageSearch
-
Tracking White Color Using Python Opencv - TouSu Developer Zone ...
-
RGB To HSV Color Conversion
-
Detecting Colors (Hsv Color Space) - Opencv With Python - Pysource
-
Color Spaces In OpenCV | Python - GeeksforGeeks
-
White Color Code (Hex RGB CMYK), Paint, Palette, Image