I am trying usd opencv + tegra tx1 camera display ( 1080 60 fps )
cpu occupancy is high and delays occur…
i try image process… opencv + cuda
is there a better solution?
code
int
main(int argc, char **argv)
{
setenv (“DISPLAY”, “:0”, 0);
//char* gst = "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)I420, framerate=(fraction)60/1 ! nvvidconv flip-method=2 ! videoconvert ! appsink";
// char* gst = “nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)60/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! ‘video/x-raw, format=(string)BGR’ ! appsink”;
char* gst = “nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)60/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink”;
if(camera.open(gst) ==false)
{
printf(“isOpened error \n”);
return 0;
}
camera.read(rawCamImage);
width = 1920;
height = 1080;
m_camBuffer = new unsigned char[width*height*3];
h_img = new unsigned char[width*height*3];
printf("Init VideoCapture \n");
int device;
struct cudaDeviceProp prop;
cudaGetDevice(&device);
cudaGetDeviceProperties(&prop, device);
initGL(&argc, argv);
//findCudaGLDevice(argc, (const char **)argv);
// initCudaBuffers();
initGLBuffers();
glutMainLoop();
exit(EXIT_SUCCESS);
}
void display()
{
camera.read(rawCamImage);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB,pbo);
glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB , width*height*3 , 0 , GL_STREAM_DRAW_ARB );
GLubyte* ptr = (GLubyte*)glMapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB , GL_WRITE_ONLY_ARB);
if( ptr )
{
memcpy(ptr , rawCamImage.data ,width*height*3 );
glUnmapBuffer(GL_PIXEL_UNPACK_BUFFER_ARB);
}
// load texture from pbo
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
glBindTexture(GL_TEXTURE_2D, texid);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
// display results
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
glTexCoord2f(0, 1);
glVertex2f(0, 0);
glTexCoord2f(1, 1);
glVertex2f(1, 0);
glTexCoord2f(1, 0);
glVertex2f(1, 1);
glTexCoord2f(0, 0);
glVertex2f(0, 1);
glEnd();
glDisable(GL_TEXTURE_2D);
glutSwapBuffers();
}