forked from microsoft/AirSim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify python getImageForCamera API
add point_cloud helper.
- Loading branch information
1 parent
a680c06
commit d051de9
Showing
3 changed files
with
49 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# use open cv to create point cloud from depth image. | ||
|
||
from PythonClient import * | ||
import cv2 | ||
import time | ||
import sys | ||
|
||
outputFile = "cloud.txt" | ||
color = (0,255,0) | ||
rgb = "%d %d %d" % color | ||
|
||
def printUsage(): | ||
print("Usage: python point_cloud.py [cloud.txt]") | ||
|
||
def savePointCloud(image, fileName): | ||
f = open(fileName, "w") | ||
for x in xrange(image.shape[0]): | ||
for y in xrange(image.shape[1]): | ||
x,y,z = image[x,y] | ||
f.write("%f %f %f %s\n" % (x, y, z, rgb)) | ||
f.close() | ||
|
||
for arg in sys.argv[1:]: | ||
cloud.txt = arg | ||
|
||
client = AirSimClient('127.0.0.1') | ||
|
||
while True: | ||
rawImage = client.getImageForCamera(0, AirSimImageType.Depth) | ||
if (rawImage == None): | ||
print("Camera is not returning image, please check airsim for error messages") | ||
sys.exit(0) | ||
else: | ||
png = cv2.imdecode(rawImage, cv2.IMREAD_UNCHANGED) | ||
savePointCloud(pnf, outputFile) | ||
print("saved " + outputFile) | ||
sys.exit(0) | ||
|
||
key = cv2.waitKey(1) & 0xFF; | ||
if (key == 27 or key == ord('q') or key == ord('x')): | ||
break; |