vscan
plantimager.vscan Link
VirtualScanner Link
VirtualScanner(width, height, focal, flash=False, host=None, port=9001, scene=None, add_leaf_displacement=False, classes=None)
Bases: AbstractScanner
A virtual scanner sending HTTP requests to a host rendering the 3D virtual plant and taking pictures.
Attributes:
Name | Type | Description |
---|---|---|
runner |
VirtualScannerRunner
|
The runner for the virtual scanner process. It must accept 'POST' & 'GET' HTTP requests. |
host |
str
|
The virtual scanner host ip. |
port |
int
|
The virtual scanner host port. |
classes |
list of str
|
The list of classes to render, must be found in the loaded OBJ. |
flash |
bool
|
If |
ext |
str
|
Extension to use to write image data from the |
position |
Pose
|
The current position of the camera. |
add_leaf_displacement |
bool
|
If |
Instantiate a VirtualScanner
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
int
|
The width of the image to acquire. |
required |
height
|
int
|
The height of the image to acquire. |
required |
focal
|
int
|
The focal distance to the object to acquire. |
required |
flash
|
bool
|
If |
False
|
host
|
str
|
The virtual scanner host ip.
By default, instantiate a local |
None
|
port
|
int
|
The virtual scanner host port.
Used only if |
9001
|
scene
|
str
|
Path to the scene file to create in the |
None
|
add_leaf_displacement
|
bool
|
If |
False
|
classes
|
list of str
|
The list of classes to generate pictures for, must be found in the loaded OBJ.
Defaults to |
None
|
Source code in plantimager/vscan.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
channels Link
channels()
List the channels to acquire.
Notes
Default to the 'rgb' channel. If classes are defined, they will be returned in addition to the default and the 'background'.
Source code in plantimager/vscan.py
438 439 440 441 442 443 444 445 446 447 448 449 |
|
get_bounding_box Link
get_bounding_box()
Returns the bounding-box coordinates from the Blender server.
Source code in plantimager/vscan.py
451 452 453 |
|
get_position Link
get_position()
Returns the current position of the camera.
Source code in plantimager/vscan.py
281 282 283 |
|
get_target_pose Link
get_target_pose(elt)
Get the target pose from a given path element (singleton).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
elt
|
PathElement
|
The path element to reach. |
required |
Returns:
Type | Description |
---|---|
Pose
|
The target pose to reach. |
Notes
If a Pose
attribute is missing from the given path element, we use the value from the previous pose.
Source code in plantimager/hal.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
grab Link
grab(idx, metadata=None)
Grab a picture using the virtual scanner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx
|
int
|
The id of the picture. |
required |
metadata
|
dict
|
The dictionary of metadata to associate to this picture. |
None
|
Returns:
Type | Description |
---|---|
DataItem
|
The picture data & metadata. |
Source code in plantimager/vscan.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
|
inc_count Link
inc_count()
Incremental counter used to return a picture index for the grab
method.
Source code in plantimager/hal.py
213 214 215 216 217 |
|
list_backgrounds Link
list_backgrounds()
List the available backgrounds.
Source code in plantimager/vscan.py
325 326 327 |
|
list_objects Link
list_objects()
List the available objects.
Source code in plantimager/vscan.py
321 322 323 |
|
load_background Link
load_background(file)
Loads a background from a HDRI file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
File
|
The file instance corresponding to the HDRI file. |
required |
Returns:
Type | Description |
---|---|
Response
|
The response from Blender Flask server to background file upload. |
See Also
romi_virtualplantimager.upload_background_post
Source code in plantimager/vscan.py
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
load_object Link
load_object(file, mtl=None, palette=None, colorize=True)
Upload the OBJ, MTL and palette files to the Blender Flask server with the POST method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
File
|
The |
required |
mtl
|
File
|
The |
None
|
palette
|
File
|
The |
None
|
colorize
|
bool
|
Whether the object should be colorized in Blender. |
True
|
Returns:
Type | Description |
---|---|
Response
|
The response from Blender Flask server after uploading the files. |
See Also
romi_virtualplantimager.upload_object_post
Notes
To avoid messing up the OBJ, MTL & PNG palette files, we create a temporary copy.
The POST method of the Blender Flask server expect:
- a 'file' argument with the BufferedReader
for the OBJ file [REQUIRED].
- a 'mtl' argument with the BufferedReader
for the MTL file [OPTIONAL].
- a 'palette' argument with the BufferedReader
for the PNG palette file [OPTIONAL].
- a 'colorize' argument as boolean [OPTIONAL].
Source code in plantimager/vscan.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
render Link
render(channel='rgb')
Use the Blender server to render an image of the virtual plant.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel
|
str
|
The name of the channel to render. If not 'rgb' grab a picture of a specific part of the virtual plant. Defaults to 'rgb', grab a picture of the whole virtual plant. |
'rgb'
|
Returns:
Type | Description |
---|---|
ndarray
|
The image array. |
Source code in plantimager/vscan.py
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
scan Link
scan(path, fileset)
Performs a scan, that is a series of movements and image acquisitions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
The path to follows to acquire image. |
required |
fileset
|
Fileset
|
The output fileset used to save the image. |
required |
Source code in plantimager/hal.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
scan_at Link
scan_at(pose, exact_pose=True, metadata=None)
Move to a given position and take a picture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pose
|
Pose
|
The position of the camera to take the picture. |
required |
exact_pose
|
bool
|
If |
True
|
metadata
|
dict
|
The dictionary of metadata to associate to this picture. |
None
|
Returns:
Type | Description |
---|---|
DataItem
|
The picture data & metadata. |
Source code in plantimager/hal.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
set_intrinsics Link
set_intrinsics(width, height, focal)
Set the intrinsic parameters of the camera for the virtual scanner.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
int
|
The width of the image to acquire. |
required |
height
|
int
|
The height of the image to acquire. |
required |
focal
|
int
|
The focal distance to the object to acquire. |
required |
Source code in plantimager/vscan.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
set_position Link
set_position(pose)
Set the new position of the camera.
Source code in plantimager/vscan.py
285 286 287 288 289 290 291 292 293 294 295 296 |
|
VirtualScannerRunner Link
VirtualScannerRunner(scene=None, port=9001)
Run a Flask server in Blender to act as the virtual scanner.
Attributes:
Name | Type | Description |
---|---|---|
subprocess |
Popen
|
The subprocess instance, initialized by the |
scene |
str
|
Path to a Blender scene file to load. |
port |
int
|
The port to use to instantiate and communicate with the Flask server in Blender. |
Notes
It initializes the flask server and then listens to HTTP requests on that port.
The process is started with the start()
method and stopped with the stop()
method.
Instantiate a VirtualScannerRunner
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scene
|
str
|
Path to a Blender scene file to load.
Defaults to |
None
|
port
|
int
|
The port to use to instantiate and communicate with the Flask server in Blender.
Defaults to |
9001
|
Source code in plantimager/vscan.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
start Link
start()
Start the Flask server in Blender.
Source code in plantimager/vscan.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
stop Link
stop()
Stop the Flask server in Blender.
Source code in plantimager/vscan.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
available_port Link
available_port(port)
Test if it is possible to listen to this port for TCP/IPv4 connections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
port
|
int
|
The localhost port to test. |
required |
Returns:
Type | Description |
---|---|
bool
|
|
Examples:
>>> from plantimager.vscan import available_port
>>> available_port(9001)
True
Source code in plantimager/vscan.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
find_available_port Link
find_available_port(port_range)
Find an available port.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
port_range
|
list of int
|
A len-2 list of integers specifying the range of ports to test for availability. |
required |
Returns:
Type | Description |
---|---|
int
|
The available port. |
Examples:
>>> from plantimager.vscan import find_available_port
>>> find_available_port([9001, 9999])
Source code in plantimager/vscan.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|