-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvertImageToArray.py
More file actions
59 lines (44 loc) · 1.2 KB
/
Copy pathconvertImageToArray.py
File metadata and controls
59 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from PIL import Image
from numpy import asarray
import os
import rospy
import math
from somthing.msg import array
import autopy
INPUT_DIRECTORY = "/home/pratham-rathi/Unity-Robotics-Hub/ROSTesting/Assets/Images"
REST_TIME = 5
def numpyPub():
#defines a topic and sends it the message file
pub = rospy.Publisher('numpyTopic', array, queue_size = 10)
#gives a name to our node
rospy.init_node('numpyPub', anonymous=True)
autopy.key.toggle('f9', True)
autopy.key.toggle('f9', False)
msg_to_publish = getArr()
#sets node frequency at 5hz
rate = rospy.Rate(REST_TIME)
pub.publish(msg_to_publish)
rate.sleep()
def getArr():
# load the image
os.chdir(INPUT_DIRECTORY)
for imageName in os.listdir(INPUT_DIRECTORY):
image = Image.open('imageName')
data = asarray(image)
os.remove(imageName)
return data
if __name__ == "__main__":
try:
numpyPub()
except rospy.ROSInterruptException:
pass
#USE FOR LATER
#print(type(data))
# summarize shape
#print(data.shape)
# create Pillow image
#image2 = Image.fromarray(data)
#print(type(image2))
# summarize image details
#print(image2.mode)
#print(image2.size)