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

Using MATLAB (a) Write a computer program capable of zooming and shrinking an image by pixel...
Using MATLAB (a) Write a computer program capable of zooming and shrinking an image by pixel replication. Assume that the desired zoom/shrink factors are integers.
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...
1. Create a color image of size 200 × 200. The image should have a blue...
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, 5 ×...
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,...
Reflection Write a program in Python or Matlab to perform reflection of an image about its...
Reflection Write a program in Python or Matlab to perform reflection of an image about its y-axis. Apply your program to an image of your choice to demonstrate the reflection. Do not use transpose library.
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.
In the C++ programming language write a program capable of playing Tic-Tac-Toe against the user. Your...
In the C++ programming language write a program capable of playing Tic-Tac-Toe against the user. Your program should use OOP concepts in its design. You can use ASCII art to generate and display the 3x3 playing board. The program should randomly decide who goes first computer or user. Your program should know and inform the user if an illegal move was made (cell already occupied). The program should also announce if one of the players wins or if a draw...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT