Merge branch 'master' of gitlab.lrz.de:robocupss18-blue3/kick-it
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import print_function
|
|||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
import cv2
|
import cv2
|
||||||
from imagereaders import VideoReader, NaoImageReader
|
from imagereaders import VideoReader, NaoImageReader, PictureReader
|
||||||
# import imutils
|
# import imutils
|
||||||
|
|
||||||
class Colorpicker(object):
|
class Colorpicker(object):
|
||||||
@@ -89,6 +89,10 @@ if __name__ == '__main__':
|
|||||||
'--video-file',
|
'--video-file',
|
||||||
help='video file to use'
|
help='video file to use'
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--image-file',
|
||||||
|
help='image to use'
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--still',
|
'--still',
|
||||||
help='only take one image from video stream',
|
help='only take one image from video stream',
|
||||||
@@ -110,6 +114,8 @@ if __name__ == '__main__':
|
|||||||
cp.load(args.input_config)
|
cp.load(args.input_config)
|
||||||
if args.video_file:
|
if args.video_file:
|
||||||
rdr = VideoReader(args.video_file, loop=True)
|
rdr = VideoReader(args.video_file, loop=True)
|
||||||
|
elif args.image_file:
|
||||||
|
rdr = PictureReader(args.image_file)
|
||||||
elif args.nao_ip:
|
elif args.nao_ip:
|
||||||
rdr = NaoImageReader(
|
rdr = NaoImageReader(
|
||||||
args.nao_ip,
|
args.nao_ip,
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import cv2
|
import cv2
|
||||||
|
try:
|
||||||
from naoqi import ALProxy
|
from naoqi import ALProxy
|
||||||
|
except:
|
||||||
|
ALProxy = None
|
||||||
|
|
||||||
|
|
||||||
class NaoImageReader(object):
|
class NaoImageReader(object):
|
||||||
@@ -54,3 +57,16 @@ class VideoReader(object):
|
|||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.cap.release()
|
self.cap.release()
|
||||||
|
|
||||||
|
|
||||||
|
class PictureReader(object):
|
||||||
|
"Dummy class for maybe convenience."
|
||||||
|
|
||||||
|
def __init__(self, filename):
|
||||||
|
self.frame = cv2.imread(filename)
|
||||||
|
|
||||||
|
def get_frame(self):
|
||||||
|
return self.frame.copy()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -1,50 +1,22 @@
|
|||||||
import numpy as np
|
|
||||||
import cv2
|
import cv2
|
||||||
from naoqi import ALProxy
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from imagereaders import NaoImageReader
|
||||||
|
import argparse
|
||||||
|
|
||||||
nao_ip = '192.168.0.11'
|
|
||||||
nao_port = 9559
|
|
||||||
res = (3, (960, 1280)) # NAOQi code and acutal resolution
|
|
||||||
fps = 1
|
|
||||||
|
|
||||||
# get NAOqi module proxy
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
# select camer
|
parser.add_argument('--res', type=int, choices=(1, 2, 3),
|
||||||
# 0: Top
|
default=3)
|
||||||
# 1: Bottom
|
parser.add_argument('--cam-id', type=int, choices=(0, 1),
|
||||||
camera=0
|
default=0)
|
||||||
|
args = parser.parse_args()
|
||||||
videoDevice = ALProxy('ALVideoDevice', nao_ip, nao_port)
|
|
||||||
subscriber = videoDevice.subscribeCamera(
|
|
||||||
"tester", camera, res[0], 13, fps
|
|
||||||
)
|
|
||||||
# create image
|
|
||||||
image = np.zeros((res[1][0], res[1][1], 3), np.uint8)
|
|
||||||
|
|
||||||
for k in range(1):
|
|
||||||
|
|
||||||
result = videoDevice.getImageRemote(subscriber)
|
|
||||||
videoDevice.releaseImage(subscriber)
|
|
||||||
|
|
||||||
|
video = NaoImageReader('192.168.0.11', res=args.res, cam_id=args.cam_id,
|
||||||
|
fps=1)
|
||||||
|
frame = video.get_frame()
|
||||||
|
video.close()
|
||||||
now = datetime.now().strftime('%Y%m%d%H%M%S')
|
now = datetime.now().strftime('%Y%m%d%H%M%S')
|
||||||
if result == None:
|
|
||||||
print 'cannot capture.'
|
|
||||||
elif result[6] == None:
|
|
||||||
print 'no image data string.'
|
|
||||||
else:
|
|
||||||
values = map(ord, list(result[6]))
|
|
||||||
i = 0
|
|
||||||
for y in range(res[1][0]):
|
|
||||||
for x in range(res[1][1]):
|
|
||||||
image.itemset((y, x, 0), values[i + 0])
|
|
||||||
image.itemset((y, x, 1), values[i + 1])
|
|
||||||
image.itemset((y, x, 2), values[i + 2])
|
|
||||||
i += 3
|
|
||||||
if camera==0:
|
|
||||||
cv2.imwrite('top' + now + '.jpg', image)
|
|
||||||
else:
|
|
||||||
cv2.imwrite('bottom' + now + '.jpg',image)
|
|
||||||
|
|
||||||
|
prefix = 'bottom' if args.cam_id else 'bottom'
|
||||||
videoDevice.unsubscribe(subscriber)
|
cv2.imwrite(prefix + now + '.jpg', frame)
|
||||||
|
|||||||
Reference in New Issue
Block a user