コード例 #1
0
class RedDetector(Thread):
	def __init__(self):
		Thread.__init__(self)
		self.camera = Camera(400,250)
		self.value = False
		print("test")
		self.run()
	

		
	def is_red(self, image):
		red_pixels = 0
		image.convert('RGB')
		pix = image.load()
		for x in range(400):
			for y in range(250):
				pixel = pix[x,y]
				#pixel = image.getpixel((x,y))
				if ((pixel[0] >= 100) and (pixel[1] >= 100) and (pixel[2] >= 100)):
					red_pixels += 1
					pix[x,y] = (0,255,0)
					#print("one red pixel added")
			percentage = red_pixels/128/96
			if percentage >= 0.05:
				self.value = True
			else:
				self.value = False
		#print(red_pixels)
		image.save("Change_color.jpeg")	
		return red_pixels

	def run(self):
		#print("trying to capture")
		self.image = self.camera.update()
            #image = Imager("image.png",self.camera.get_value())
		pixel = self.is_red(self.image)
		if (pixel > 30):
			GPIO.output(output, False)
		else:
			GPIO.output(output, True)
		#self.camera.close()

	def get_value(self):
		return self.value

	def update(self):
		pass
コード例 #2
0
ファイル: image.py プロジェクト: ustc-mbit/time
class Image:
    def __init__(self):
        # 实例化相机
        self.cam = Camera()
        self.n = 0
        self.image = np.zeros([600, 800, 3], np.uint8)
        self.image1 = np.zeros([600, 800, 3], np.uint8)

    def enhancebri(self, m):
        self.n = self.n + 1
        frame = self.cam.run()
        frame1 = cv2.flip(frame, 0)
        # frame = cv2.resize(frame, (800, 600))
        # frame1 = cv2.GaussianBlur(frame1, (5, 5), 1.5)
        self.image = cv2.add(frame1, self.image)
        if self.n % m == 0:
            self.n = 0
            self.image1 = self.image
            self.image = np.zeros([600, 800, 3], np.uint8)
            return self.image1
        print('self.n', self.n)

    def closecamera(self):
        mvsdk.CameraUnInit(self.cam.hCamera)


# Cam = Camera()
# n = 0
#
# m = 6
# Img = Image()
# while 1:
#     n = n + 1
#     # frame = Cam.run()
#     # frame1 = cv2.flip(frame, 0)
#     frame1 = Img.enhancebri(m)
#     if n % m == 0:
#         # frame1 = Img.enhancebri(5)
#         cv2.imshow('1', frame1)
#         cv2.waitKey(1)
#         n = 0
#     print('n', n)
コード例 #3
0
ファイル: image.py プロジェクト: ustc-mbit/time
class Image:
    def __init__(self, width, height):
        # 实例化相机
        self.cam = Camera()
        self.n = 0
        self.image = np.zeros([height, width, 3], np.uint8)
        self.image1 = np.zeros([height, width, 3], np.uint8)

    def enhancebri(self, m):
        self.n = self.n + 1
        frame = self.cam.run()
        frame1 = cv2.flip(frame, 0)
        frame1 = cv2.resize(frame1, (800, 600))
        # frame1 = cv2.GaussianBlur(frame1, (5, 5), 1.5)
        self.image = cv2.add(frame1, self.image)
        if self.n % m == 0:
            self.n = 0
            self.image1 = self.image
            self.image = np.zeros([600, 800, 3], np.uint8)
            return self.image1
        print('self.n', self.n)

    def closecamera(self):
        mvsdk.CameraUnInit(self.cam.hCamera)
コード例 #4
0
def video_feed():
    """Video streaming route. Put this in the src attribute of an img tag."""
    return Response(gen(Camera()),
                    mimetype='multipart/x-mixed-replace; boundary=frame')
コード例 #5
0
import cv2
import sys
from camera1 import Camera
from window import Window

if __name__ == '__main__':
    # 实例化相机对象
    cam = Camera()
    # 生成窗体对象
    pro = Window('projector_1', 'projector_2', 1600, 1200)
    # 前两个参数是第一个窗体,后两个是第二个窗体
    pro.createwindow(1600, 1200)
    # 连投影仪运行这句话,不连就把1改成0,否则会报错 out of range
    pro.movewindow(1)
    # 前两个参数是一屏二屏标记的颜色,第三个参数是标记的宽度,最后两个参数 要和生成窗体对象的最后两个参数保持一致,如果想要二屏标记也是绿色就把(255,255,255)改成(0,255,0)
    pro.bindingwi((0, 255, 0), (255, 255, 255), 3, 1600, 1200)
    pro.nobiaotilan()
    # 创建跟踪器
    tracker_type = 'CSRT'
    tracker = cv2.TrackerCSRT_create()
    while True:
        # 读入第一帧
        frame = cam.run()
        frame = cv2.flip(frame, 0)
        # print(frame.shape)
        # pro.addimage(frame)
        pro.showimage(frame)
        cv2.waitKey(1)
        pro.movebiaoji()
        # 定义一个bounding box
        # bbox = (287, 23, 86, 320)
コード例 #6
0
	def __init__(self):
		Thread.__init__(self)
		self.camera = Camera(400,250)
		self.value = False
		print("test")
		self.run()
コード例 #7
0
ファイル: image.py プロジェクト: ustc-mbit/time
 def __init__(self):
     # 实例化相机
     self.cam = Camera()
     self.n = 0
     self.image = np.zeros([600, 800, 3], np.uint8)
     self.image1 = np.zeros([600, 800, 3], np.uint8)
コード例 #8
0
ファイル: image.py プロジェクト: ustc-mbit/time
 def __init__(self, width, height):
     # 实例化相机
     self.cam = Camera()
     self.n = 0
     self.image = np.zeros([height, width, 3], np.uint8)
     self.image1 = np.zeros([height, width, 3], np.uint8)