Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 仅从OpenCV中的边界框(ROI)提取颜色特征_Python_Opencv_Image Processing_Colors_Image Segmentation - Fatal编程技术网

Python 仅从OpenCV中的边界框(ROI)提取颜色特征

Python 仅从OpenCV中的边界框(ROI)提取颜色特征,python,opencv,image-processing,colors,image-segmentation,Python,Opencv,Image Processing,Colors,Image Segmentation,我只想从边界框(ROI)中提取颜色特征,而忽略OpenCV中使用python的实时视频中图像的其余部分 我试过了,但我做不到,它画了人类(我的案例)的颜色边界框(ROI)和另一个问题,我选择了红色,它画的东西轮廓不是红色的 这是我的完整代码: from imutils.video import VideoStream from imutils.video import FPS import numpy as np import imutils import time import cv2 fro

我只想从边界框(ROI)中提取颜色特征,而忽略OpenCV中使用python的实时视频中图像的其余部分

我试过了,但我做不到,它画了人类(我的案例)的颜色边界框(ROI)和另一个问题,我选择了红色,它画的东西轮廓不是红色的

这是我的完整代码:

from imutils.video import VideoStream
from imutils.video import FPS
import numpy as np
import imutils
import time
import cv2
from shapely.geometry import Polygon
import operator
CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
COLORS = np.random.uniform(0, 255, size=(len(CLASSES), 3))
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe('prototxt.txt', 'caffemodel')
print("[INFO] starting video stream...")
vs = cv2.VideoCapture(0)
time.sleep(2.0)
fps = FPS().start()
width = vs.get(3)  # float
height = vs.get(4)  # float
print width, height

fps = FPS().start()
while True:
    ret, frame = vs.read()
    (h, w) = frame.shape[:2]
    blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 0.007843, (300, 300), 127.5)
    net.setInput(blob)
    detections = net.forward()
    big_area = 0
    big_center = 320
    detected = 0
    dimensions_body = []
    for i in np.arange(0, detections.shape[2]):
        confidence = detections[0, 0, i, 2]
        object_type = int(detections[0, 0, i, 1])
        if object_type == 15 and confidence > 0.2:
            box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
            (startX, startY, endX, endY) = box.astype("int")
            label = "{}: {:.2f}%".format('person', confidence * 100)
            cv2.rectangle(frame, (startX, startY), (endX, endY), [0, 0, 255], 2)
            ROI = frame[startX:endX, startY:endY]
            hsv = cv2.cvtColor(ROI, cv2.COLOR_BGR2HSV)
            green_lower = np.array([136, 87, 111], np.uint8)
            green_upper = np.array([180, 255, 255], np.uint8)
            green = cv2.inRange(ROI, green_lower, green_upper)
            kernal = np.ones((5, 5), "uint8")
            # red = cv2.dilate(green, kernal)
            res_red = cv2.bitwise_and(ROI, ROI, mask=green)
            # Tracking blue
            (_, contours, hierarchy) = cv2.findContours(green, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
            for pic, contour in enumerate(contours):
                area1 = cv2.contourArea(contour)
                if (area1 > 300):
                    x1, y1, w1, h1 = cv2.boundingRect(contour)
                    img = cv2.rectangle(frame, (x1, y1), (x1 + w1, y1 + h1), (255, 0, 0), 2)
                    cv2.putText(frame, "green Colour", (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 0, 0))
    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break
    fps.update()
    fps.stop()
vs.release()
cv2.destroyAllWindows()
数据


请帮助我或提供任何建议

你说的“色彩特征”是什么意思?你到底想得到什么?你的投资回报率是多少?@pip1726,首先,感谢你的帮助。这个问题由来已久。我的论文中使用了它。看看你是否愿意