ayman2
December 12, 2023, 6:59pm
1
I am trying to set data coming from opencv’s goodFeaturesToTrack to vpiSubmitOpticalFlowPyrLK, this requires I set a vpiArray type, how can I do this in vpi v3. I don’t see any samples to do this.
Also I know there is a HarrisCornerDetector which will output features in the right format, however, I have found that goodFeaturesToTrack produces better candidate features.
ayman2
December 12, 2023, 8:24pm
2
#include <vpi/Array.h>
#include <vpi/ArrayType.h>
#include <vpi/Status.h>
#include <opencv2/opencv.hpp>
#define CHECK_STATUS(STMT) \
do { \
VPIStatus status__ = (STMT); \
if (status__ != VPI_SUCCESS) { \
char buffer[VPI_MAX_STATUS_MESSAGE_LENGTH]; \
vpiGetLastStatusMessage(buffer, sizeof(buffer)); \
std::ostringstream ss; \
ss << vpiStatusGetName(status__) << ": " << buffer; \
throw std::runtime_error(ss.str()); \
} \
} while (0);
int main(int argc, char** argv) {
// Test VPI reading and writing primitives
VPIArray array = NULL;
VPIArrayType format = VPI_ARRAY_TYPE_KEYPOINT_F32;
// Create empty array on the vpi side
vpiArrayCreate(0, format, 0, &array);
// Create a array of opencv points
std::vector<cv::Point2f> points_opencv;
std::vector<VPIKeypointF32> points;
points_opencv.push_back(cv::Point2f(1.0, 2.0));
// Copy the points to the VPI array
for (auto& point : points_opencv) {
points.push_back(VPIKeypointF32{point.x, point.y});
}
VPIArrayData data_from_opencv;
data_from_opencv.bufferType = VPI_ARRAY_BUFFER_HOST_AOS;
data_from_opencv.buffer.aos.capacity = points.capacity();
data_from_opencv.buffer.aos.type = format;
int32_t size = points.size();
data_from_opencv.buffer.aos.sizePointer = &size;
data_from_opencv.buffer.aos.strideBytes = sizeof(VPIKeypointF32);
data_from_opencv.buffer.aos.data = &points[0];
CHECK_STATUS(vpiArrayCreateWrapper(&data_from_opencv, 0, &array));
VPIArrayData data;
// Lock the array for reading
CHECK_STATUS(vpiArrayLockData(array, VPI_LOCK_READ,
VPI_ARRAY_BUFFER_HOST_AOS, &data));
// Check that the data is the same
if (data.buffer.aos.capacity != data_from_opencv.buffer.aos.capacity) {
std::cout << "Size mismatch" << std::endl;
std::cout << "VPI: " << data.buffer.aos.capacity << std::endl;
std::cout << "OpenCV: " << data_from_opencv.buffer.aos.capacity
<< std::endl;
// Print vpi data type
std::cout << "VPI data type: " << data.buffer.aos.type << std::endl;
}
// Try to access the first element
VPIKeypointF32* first_element = (VPIKeypointF32*)data.buffer.aos.data;
std::cout << "First element: " << first_element->x << ", "
<< first_element->y << std::endl;
// Unlock the array
CHECK_STATUS(vpiArrayUnlock(array));
// Destroy the array
vpiArrayDestroy(array);
}
Read the docs, i was in a mix up thinking I was using vpi2 but I had vpi3 installed, leaving this here for anyone interested in the future.
Hi,
Could you double-check your VPI version?
Since VPI 3 is from JetPack 6 which is only available for the Orin series.
Thanks.
system
Closed
January 3, 2024, 5:38am
6
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.