Click here to Skip to main content
16,015,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to detect Red , Green and blue images on the one frame. i already have code with red color detection. i can change blue and green detection by changing lower and upper limit of the color. but i cant get together 3 colour in same window. other wise i want to create contours on the images.

What I have tried:

this is my code
# import the necessary packages
from picamera.array import PiRGBArray #As there is a resolution problem in raspberry pi, will not be able to capture frames by VideoCapture
from picamera import PiCamera
from array import array
import RPi.GPIO as GPIO
import time
import cv2
import cv2.cv as cv
import numpy as np
import serial
import datetime
import os


#CAMERA CAPTURE
#initialize the camera and grab a reference to the raw camera capture
width=400
hight=50

camera = PiCamera()
camera.resolution = (width, hight)
camera.framerate =30

rawCapture = PiRGBArray(camera, size=(width, hight))
camera.hflip=True
camera.vflip=True
# allow the camera to warmup
time.sleep(0.001)
thrsld=30


# capture frames from the camera
for image in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
#grab the raw NumPy array representing the image, then initialize the timestamp and occupied/unoccupied text
frame = image.array
frame=cv2.flip(frame,1)
hsv = cv2.cvtColor(frame, cv2.cv.CV_BGR2HSV)

lower_red=np.array([70,150,50],dtype=np.uint8)
upper_red=np.array([255,255,180],dtype=np.uint8)
mask_red=cv2.inRange(hsv,lower_red,upper_red)





cv2.imshow("red",mask_red)
cv2.imshow("draw",frame)
rawCapture.truncate(0) # clear the stream in preparation for the next frame

if(cv2.waitKey(1) & 0xff == ord('q')):
GPIO.cleanup()

break
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900