Question

In: Computer Science

Write a program that is capable of detecting the color brown in an image taken by...

Write a program that is capable of detecting the color brown in an image taken by a webcam using OpenCV python code.

Solutions

Expert Solution

# Python program for detection of a specific color ( brown here) using OpenCV with Python

import cv2

import numpy as np

# Webcamera no 0 is used to capture the frames

cap = cv2.VideoCapture(0)

# This drives the program into an infinite loop.

while(1):

# Captures the lives stream frame by frame

_, frame =cap.read()

# Converts image from BGR to HSV

hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

lower_red = np.array([110,50,50])

upper_red = np.array([130,255,255])

#Here we are defining range of brown color in HSV

#This creates a mask of brown coloured

#objects found in the frame .

mask =cv2.inRange(hsv, lower_red, upper_red)

# The bitwise and of the frame and mask is done so

# that only the brown coloured objects are highlighted

# and stored in res

res = cv2.bitwise_and(frame,frame,mask=mask)

cv2.imshow('frame',frame)

cv2.imshow('mask',mask)

cv2.imshow('res',res)

# This displays the frame , mask

#and res which we created in 3 separate windows.

k = cv2.waitKey(5) & 0xFF

if k ==27:

break

# Destroys all of the HighGUI windows.

cv2.destroyALLWindows()

# release the captured frame

cap.release()


Related Solutions

Language Python with functions and one main function Write a program that converts a color image...
Language Python with functions and one main function Write a program that converts a color image to grayscale. The user supplies the name of a file containing a GIF or PPM image, and the program loads the image and displays the file. At the click of the mouse, the program converts the image to grayscale. The user is then prompted for a file name to store the grayscale image in.
YOU MUST CONFIGURE AN HPLC SYSTEM THAT IS CAPABLE OF SEPARATING THE ANALYTES, DETECTING THE ANALYTES,...
YOU MUST CONFIGURE AN HPLC SYSTEM THAT IS CAPABLE OF SEPARATING THE ANALYTES, DETECTING THE ANALYTES, DETERMINING THE MOLECULAR WEIGHTS OF THE ANALYTES, AND ESTIMATING THE AMOUNTS OF THE ANALYTES IN EACH SAMPLE MIXTURE. YOU MUST SELECT FROM THE FOLLOWING OPTIONS BELOW 1.PUMPS: LOW PRESSURE MIXING OR HIGH PRESSURE MIXING 2.COLUMN STATIONARY PHASE 3.COLUMN TEMPERATURE CONTROL YES OR NO 4.ISOCRATIC OR GRADIENT SEPARATION 5.MOBILE PHASE COMPOSITION 6.SEPARATION CONDITIONS-FLOW RATE, RUN TIME, GRADIENT TIME (IF USED) 7.DETECTOR(S) TO BE USED 8.METHOD...
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to...
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to binary and gray scale, Image segmentation and extraction, draw and find the region of interest with a circle, Plot bounding box, Region extraction and histogram. 2- Write a MATLAB program to Design a GUI calculator which is as shown in below figure 1. Add tool bar options to the GUI calculator and Highlight specific codes written in program and signify the steps followed.
Write a program that creates an image of green and white horizontal stripes. Your program should...
Write a program that creates an image of green and white horizontal stripes. Your program should ask the user for the size of your image, the name of the output file, and create a .png file of stripes. For example, if the user enters 10, your program should create a 10x10 image, alternating between green and white stripes. A sample run of the program: Enter the size: 10 Enter output file: 10stripes.png Another sample run of the program: Enter the...
Using Matlab 1. Create a color image of size 200 × 200. The image should have...
Using Matlab 1. Create a color image of size 200 × 200. The image should have a blue background. 2. Create 100 yellow regions within the image that have a variable size. More specifically, their width should be an odd number and vary between 3 and 7 and their height should also be an odd number and vary between 3 and 7. For example, you may get rectangular regions of size 3 × 3, 3 × 5, 5 × 3,...
Write a program to draw a Pentagon with blue color inside a window. Using C ++...
Write a program to draw a Pentagon with blue color inside a window. Using C ++ with Output.
A heterozygous brown-eyed human female who is color blind marries a homozygous brown-eyed male who is...
A heterozygous brown-eyed human female who is color blind marries a homozygous brown-eyed male who is not color-blind (remember, color-blindness is sex-linked).  Assume that eye color is an autosomal trait and that brown is dominant over blue. a. Write out genotypes of parents and the Punnett squares for the possible offspring below first (Use the table feature to help and clearly label parental and offspring genotypes): *What is the probability that any of the offspring produced have the following traits?  (please provide...
In dogs, the allele for black coat color (B) is dominant to the allele for brown...
In dogs, the allele for black coat color (B) is dominant to the allele for brown coat color (b). But if a dog has two copies of the recessive allele for a pigment-depositing gene (e), it can only have yellow coat color. In a cross of two doubly heterozygous black dogs (BbEe x BbEe), what fraction of the next generation would we expect to be yellow? WHY? a.1/8 b.1/4 c.2/3 d.3/16
You are studying a population of geese in which there are two color phases, brown and...
You are studying a population of geese in which there are two color phases, brown and gray. Color in this species is controlled by a single gene, with brown dominant to gray. A random sample of 500 geese shows that 45 are gray. What percentage of the brown geese are heterozygous?
Suppose that goats have one gene that codes for color, where A is brown and a...
Suppose that goats have one gene that codes for color, where A is brown and a is white. The goats also have another gene that codes for height, where B is tall and b is short. If these two genes are unlinked, what is the probability that a cross between Aa Bb × Aa bb parents will produce two out of six offspring that are brown and short? Enter your answer as a decimal, rather than as a percentage. waht...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT