Python 需要边缘检测方面的帮助吗
我正在尝试检测使用HSV方法从RGB相机获取的实时照片的限制 我找到了范围颜色并尝试使用凸面外壳,但它将每个部分单独标记 首先,我将其转换为HSV照片:Python 需要边缘检测方面的帮助吗,python,image,opencv3.0,convex-hull,hsv,Python,Image,Opencv3.0,Convex Hull,Hsv,我正在尝试检测使用HSV方法从RGB相机获取的实时照片的限制 我找到了范围颜色并尝试使用凸面外壳,但它将每个部分单独标记 首先,我将其转换为HSV照片: import numpy as np import matplotlib.pyplot as plt import matplotlib.image as mpimg from skimage import data from skimage.color import rgb2hsv from skimage.color import hsv
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from skimage import data
from skimage.color import rgb2hsv
from skimage.color import hsv2rgb
RGB= mpimg.imread('/home/komodo/Yasmin_new/123.jpg')
NIHSV= rgb2hsv(RGB)
RGBHSV= rgb2hsv(RGB)
h = RGBHSV[:,:,0]
s= RGBHSV[:,:,1]
v = RGBHSV[:,:,2]
m = len(h)
n = len(h[0])
for i in range(len(h)):
for j in range(len(h[0])):
if h[i,j]<=0.13 and s[i,j]> 0.18 and v[i,j]>0.8:
h[i,j] = 1
s[i, j] = 1
v[i, j] = 1
#plt.figure()
#imgplot=plt.imshow(h)
#plt.figure()
#imgplot1=plt.imshow(s)
#plt.figure()
#imgplot2=plt.imshow(v)
NIHSV[:,:,0] = h
NIHSV[:,:,1] = s
NIHSV[:,:,2] = v
H = hsv2rgb(NIHSV)
plt.figure()
imgplot=plt.imshow(H)
plt.show(imgplot)
以下是我从这段代码中得到的信息:
我想要的是:
# USAGE
# python detect_shapes.py --image shapes_and_colors.png
import sys
# import the necessary packages
# from pyimagesearch.shapedetector import ShapeDetector
# import argparse
# import imutils
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')
import numpy as np
import cv2
import time
import socket
import time
import struct
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
blurred_frame = cv2.GaussianBlur(frame, (5, 5), 0)
hsv = cv2.cvtColor(blurred_frame, cv2.COLOR_BGR2HSV)
lower_red = np.array([0, 46, 204])
upper_red = np.array([23, 255, 255])
mask = cv2.inRange(hsv, lower_red, upper_red)
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # convert to grayscale
# blur = cv2.blur(mask, (3, 3)) # blur the image
ret, thresh = cv2.threshold(mask, 50, 255, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# create hull array for convex hull points
hull = []
# calculate points for each contour
for i in range(len(contours)):
# creating convex hull object for each contour
hull.append(cv2.convexHull(contours[i], False))
# create an empty black image
drawing = np.zeros((thresh.shape[0], thresh.shape[1], 3), np.uint8)
# draw contours and hull points
for i in range(len(contours)):
color_contours = (0, 255, 0) # green - color for contours
color = (255, 0, 0) # blue - color for convex hull
# draw ith contour
cv2.drawContours(drawing, contours, i, color_contours, 1, 8, hierarchy)
# draw ith convex hull object
cv2.drawContours(drawing, hull, i, color, 1, 8)
cv2.imshow("Frame", frame)
cv2.imshow("Mask", drawing)
key = cv2.waitKey(1)
time.sleep(0.5)
if key == 27:
break
cap.release()
cv2.destroyAllWindows()