Example

TM NPU MicroPython

Product
SIMACTIC S7-1500 TM NPU 2.0
Language
en-US
Category
Manual

#...

 

#Initialize camera

pfd_gige = "UYVY"

cam_info_external_gige = camera.camera(camera_id="EXTERNAL_IMAGE", resolution=(1280, 720), pixel_format_description=pfd_gige)

 

#Define filepath

pathSdcardRoot = '/media/mmcsd-0-0/'

filePath = pathSdcardRoot+'USERDATA/'

 

#Load image from sdcard

image = None

with sdcard.open(filePath + 'rawImage.yuv', 'rb') as fp:

     image = fp.read()

 

#Preprocess image in video pipeline

vid_pipeline.init(camera=cam_info_external_gige,

     target_resolution=(224, 224),

     target_format="RGB",

     target_normalization=(0.0, 1.0),

     target_output="float",

     shaves_scaling=4,

     shaves_conversion=4)

 

#set external image

vid_pipeline.set_Image(image)

 

vid_pipeline.start_streaming(1)

 

with vid_pipeline.read_processed() as frame:

          # Save rgb image to sdcard after pipeline

     imgNameProcessed = "processedImage"

     with sdcard.open(filePath + imgNameProcessed, 'w') as fp:

          fp.write(frame.data())

 

          # #running neural network

     results = net.run(frame.data())

 

vid_pipeline.stop_streaming()

 

#...