コード例 #1
0
def find_camera():
	global camera
	
	cidx = CAMERA_START_INDEX

	while True :
		try:
			if camera:
				del(camera)

			print(cidx)

			camera = Camera(cidx, 10)
			camera.set(3, CAMERA_WIDTH)
			camera.set(4, CAMERA_HEIGHT)
			camera.set(5, 20)

			cidx = cidx + 1
			if cidx > CAMERA_MAX_INDEX:
				cidx = CAMERA_START_INDEX

			if camera == None:
				print("none")

			im = camera.get_image()

			if im == None:
				continue

			h,w,_ = im.shape

			print("%d, %d" % (h, w))

			if w < 1 or h < 1:
				continue
		
			if SHOW_IMAGE :
				cv2.imshow("image", im)

			break

		except (KeyboardInterrupt, SystemExit):
			sys.exit()
		except:
			time.sleep(0.01)
			pass
コード例 #2
0
SHOW_IMAGE = True
USE_VISION = True
CAMERA_WIDTH = 480.0
CAMERA_HEIGHT = 270.0
HEIGHT_DIFF = (21.75 - 13.25) * 0.0254  # meters

# functions

def connectionListener(conn, inf):
        print(inf, '; Connected=%s' % conn)


# init
camera = Camera(1, 10)
camera.set(3, CAMERA_WIDTH)
camera.set(4, CAMERA_HEIGHT)
camera.set(5, 20)

NetworkTable.setIPAddress("roboRIO-6731-FRC.local")
NetworkTable.setClientMode()
NetworkTable.initialize()

vtable = NetworkTable.getTable("vision")

NetworkTable.addConnectionListener(connectionListener, immediateNotify=True)

if SHOW_IMAGE :
        cv2.startWindowThread()
        cv2.namedWindow("image")
        cv2.imshow("image", camera.get_image())