This image read at 10 second program
import cv2
img=cv2.imread('lena.gif', 1)
cv2.imshow("image", img)
cv2.waitKey(1000000)
cv2.destroyAllWindows()
Video capturing with colour
import cv2
capture=cv2.VideoCapture(0)
while(True):
ret, frame=capture.read(0)
cv2.imshow('image',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
Video capturing with Black and white.
import cv2
capture=cv2.VideoCapture(0)
while(True):
ret, frame=capture.read(0)
gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('image',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()
Drawing Tools
import cv2
image=cv2.imread("lena.jpg",1)
cv2.line(image,(0,0),(510,510),(255,0,0),5)
cv2.line(image,(510,0),(0,510),(255,0,0),5)
cv2.rectangle(image,(150,150),(350,350),(0,255,0),4)
cv2.circle(image,(100,100),50,(0,0,254),-1)
cv2.circle(image,(420,100),50,(0,0,254),-1)
cv2.circle(image,(100,420),50,(0,0,254),-1)
cv2.circle(image,(420,420),50,(0,0,254),-1)
font=cv2.FONT_ITALIC
cv2.putText(image,"yaseen",(175,270),font,1.5,(10,56,167),5)
cv2.imshow("image",image)
cv2.waitKey()
cv2.destroyAllWindows()
Mouse kit:
import cv2
def draw_circle(event,x,y,flag,param):
if event == cv2.EVENT_LBUTTONDBLCLK:
cv2.circle(image,(x,y),75,(0,255,0),-1)
image=cv2.imread("lena.jpg",1)
cv2.namedWindow("image")
cv2.setMouseCallback("image",draw_circle)
while (1):
cv2.imshow('image', image)
if cv2.waitKey(20) & 0xFF ==27:
break
cv2.destroyAllWindows()
Image: BGR to HSV
import cv2
image=cv2.imread('blue.jpg',1)
new_image=cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
cv2.imshow("hsvimage",new_image,)
cv2.waitKey(0)
cv2.destroyAllWindows()
image colour senser:
import cv2
import numpy as np
image=cv2.imread('blue.jpg',1)
new_image=cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
cv2.imshow("hsvimage",new_image,)
lower_blue=np.array([110,50,50])
upper_blue=np.array([130,252,255])
mask=cv2.inRange(new_image, lower_blue, upper_blue)
cv2.imshow("mask",mask)
res=cv2.bitwise_and(image,image,mask=mask)
cv2.imshow('res',res)
cv2.waitKey(0)
cv2.destroyAllWindows()
video scanning specific colour:
import cv2
import numpy as np
cap=cv2.VideoCapture(0)
while(1):
_, frame=cap.read()
image=cv2.imread('blue.jpg',1)
new_image=cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
#cv2.imshow("hsvimage",new_image,)
lower_blue=np.array([110,50,50])
upper_blue=np.array([130,252,255])
mask=cv2.inRange(new_image, lower_blue, upper_blue)
cv2.imshow("mask",mask)
res=cv2.bitwise_and(frame,frame,mask=mask)
cv2.imshow('res',res)
k=cv2.waitKey(5) & 0xFF
if k==27:
break
cv2.destroyAllWindows()
No comments