Opencv的视频捕捉功能+多线程

import cv2
import numpy as np
from matplotlib import pyplot as plt
import threading
#其中0表示调用笔记本的内置摄像头
cam = cv2.VideoCapture(0)
(ret, img) = cam.read()
img2 = img
img3 = img
img4 = img

def sift_thread():
	sift = cv2.xfeatures2d.SIFT_create()
	(kps, descs) = sift.detectAndCompute(gray, None)
	cv2.drawKeypoints(gray, kps, img, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
	cv2.imshow('SIFT Algorithm', img)


def surf_thread():
	surf = cv2.xfeatures2d.SURF_create()
	(kps2, descs2) = surf.detectAndCompute(gray, None)
	cv2.drawKeypoints(gray, kps2, img2, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
	cv2.imshow('SURF Algorithm', img2)

def fast_thread():
	fast = cv2.FastFeatureDetector_create()
	kps3 = fast.detect(gray, None)
	cv2.drawKeypoints(gray, kps3, img3, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
	cv2.imshow('FAST Algorithm', img3)

def orb_thread():
	orb = cv2.ORB_create()
	kps4 = orb.detect(gray, None)
	(kps4, des4) = orb.compute(gray, kps4)
	cv2.drawKeypoints(gray, kps4, img4, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
	cv2.imshow('ORB Algorithm', img4)

while True:
	(ret, img) = cam.read()
	gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
	t1 = threading.Thread(name = 'SIFT Algorithm', target = sift_thread)
	t2 = threading.Thread(name = 'SURF Algorithm', target = surf_thread)
	t3 = threading.Thread(name = 'FAST Algorithm', target = fast_thread)
	t4 = threading.Thread(name = 'ORB Algorithm', target = orb_thread)
	t1.start()
	t2.start()
	t3.start()
	t4.start()
	t1.run()
	t2.join()
	t3.join()
	t4.join()

	if cv2.waitKey(1) == 27:
		break

cv2.destroyAllWindows()

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值