VPI Samples - lock_cpu() - AttributeError: 'vpi.Image' object has no attribute 'lock_cpu'
Mar 04, 2024
Hi,
I have Jetson AGX Xavier. I want to use vpi python library with python3.6.9 version. I run the sample application codes at the link bellow.
https://docs.nvidia.com/vpi/
Every sample code return the same error:
‘vpi.Image’ object has no attribute ‘lock_cpu’
Sample code:
import cv2
import sys
import vpi
import numpy as np
from argparse import ArgumentParser
# ----------------------------
# Parse command line arguments
parser = ArgumentParser()
parser.add_argument('backend', choices=['cpu','cuda','pva'],
help='Backend to be used for processing')
parser.add_argument('input',
help='Input image on which harris corners will be detected')
args = parser.parse_args();
if args.backend == 'cpu':
backend = vpi.Backend.CPU
elif args.backend == 'cuda':
backend = vpi.Backend.CUDA
else:
assert args.backend == 'pva'
backend = vpi.Backend.PVA
# --------------------------------------------------------------
# Load input into a vpi.Image and convert it to grayscale, signed 16bpp
with vpi.Backend.CUDA:
input = vpi.asimage(cv2.imread(args.input), vpi.Format.BGR8).convert(vpi.Format.S16)
with backend:
corners, scores = input.harriscorners(sensitivity=0.01)
# ---------------------------------------
# Render the keypoints in the output image
out = input.convert(vpi.Format.BGR8, backend=vpi.Backend.CUDA)
if corners.size > 0:
with out.lock_cpu() as out_data, scores.lock_cpu() as scores_data, corners.lock_cpu() as corners_data:
cmap = cv2.applyColorMap(np.arange(0, 256, dtype=np.uint8), cv2.COLORMAP_HOT)
maxscore = scores_data.max()
for i in range(corners.size):
color = tuple([int(x) for x in cmap[255*scores_data[i]//maxscore,0]])
kpt = tuple(corners_data[i].astype(np.int16))
cv2.circle(out_data, kpt, 3, color, -1)
# -------------------
# Save result to disk
cv2.imwrite('harris_corners_python'+str(sys.version_info[0])+'_'+args.backend+'.png', out.cpu())
Thank you in advance…