性能:两路2448*2048 basyer相机编码,编码后25fps,延迟200ms左右

编码:调用nvidia底层的api, 参考tegra_multimedia_api下的cuda_encode例子。只需要修改read_from_file()函数的数据为相机输入数据即可

目前只支持输入I420格式,但是basyer相机没有I420的格式,用cuda做转换,代码如下:

// Grab.cpp
/*Note: Before getting started, Basler recommends reading the Programmer's Guide topicin the pylon C++ API documentation that gets installed with pylon.If you are upgrading to a higher major version of pylon, Basler alsostrongly recommends reading the Migration topic in the pylon C++ API documentation.This sample illustrates how to grab and process images using the CInstantCamera class.The images are grabbed and processed asynchronously, i.e.,while the application is processing a buffer, the acquisition of the next buffer is donein parallel.The CInstantCamera class uses a pool of buffers to retrieve image datafrom the camera device. Once a buffer is filled and ready,the buffer can be retrieved from the camera object for processing. The bufferand additional image data are collected in a grab result. The grab result isheld by a smart pointer after retrieval. The buffer is automatically reusedwhen explicitly released or when the smart pointer object is destroyed.
*/// Include files to use the PYLON API.#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
#    include <pylon/PylonGUI.h>
#endif
#include"opencv2/opencv.hpp"
#include"opencv2/highgui.hpp"#include<sys/time.h>
#include"opencv2/core/core.hpp"
#include <pylon/gige/BaslerGigECamera.h>
#include <cuda_runtime.h>
#include "cudaYUV.h"
#include "cudaRGB.h"
//定义是否保存图片 0-否 1-是
#define saveImages 0
//定义是否记录视频 0-否 1-是
#define recordVideo 0// Namespace for using pylon objects.
using namespace Pylon;// Namespace for using cout.
using namespace std;
#include "opencv2/gpu/gpu.hpp"using namespace cv;
// Number of images to be grabbed.
static const uint32_t c_countOfImagesToGrab = 1000000;unsigned char *I420Buffer=NULL;
unsigned char *BGRABuffer=NULL;
unsigned char *RGBBuffer=NULL;/*void BGR_YUV420(unsigned char*bsrc,unsigned char *bdst,int width,int height)
{}*/
int main(int argc, char* argv[])
{// The exit code of the sample application.int exitCode = 0;// Before using any pylon methods, the pylon runtime must be initialized.Pylon::PylonAutoInitTerm autoInitTerm;  try  {  //创建相机对象(以最先识别的相机)CInstantCamera camera(CTlFactory::GetInstance().CreateFirstDevice());  // 打印相机的名称std::cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;  //获取相机节点映射以获得相机参数GenApi::INodeMap& nodemap = camera.GetNodeMap();  //打开相机camera.Open();  //获取相机成像宽度和高度GenApi::CIntegerPtr width = nodemap.GetNode("Width");  GenApi::CIntegerPtr height = nodemap.GetNode("Height");  //设置相机最大缓冲区,默认为10camera.MaxNumBuffer = 5;  // 新建pylon ImageFormatConverter对象.CImageFormatConverter formatConverter;  //确定输出像素格式formatConverter.OutputPixelFormat = PixelType_RGB8packed;  // 创建一个Pylonlmage后续将用来创建OpenCV imagesCPylonImage pylonImage;  //声明一个整形变量用来计数抓取的图像,以及创建文件名索引int grabbedlmages = 0;  // 新建一个OpenCV video creator对象.VideoWriter cvVideoCreator;  //新建一个OpenCV image对象.Mat openCvImage;  Mat dst_image;// 视频文件名std::string videoFileName = "openCvVideo.avi";  // 定义视频帧大小cv::Size frameSize = Size((int)width->GetValue(), (int)height->GetValue());  //设置视频编码类型和帧率,有三种选择// 帧率必须小于等于相机成像帧率cvVideoCreator.open(videoFileName, CV_FOURCC('D', 'I', 'V','X'), 10, frameSize, true);  //cvVideoCreator.open(videoFileName, CV_F0URCC('M','P',,4','2’), 20, frameSize, true);//cvVideoCreator.open(videoFileName, CV_FOURCC('M', '3', 'P', 'G'), 20, frameSize, true);// 开始抓取c_countOfImagesToGrab images.//相机默认设置连续抓取模式camera.StartGrabbing(c_countOfImagesToGrab, GrabStrategy_LatestImageOnly);  //抓取结果数据指针CGrabResultPtr ptrGrabResult;  // 当c_countOfImagesToGrab images获取恢复成功时,Camera.StopGrabbing()//被RetrieveResult()方法自动调用停止抓取FILE *fp=fopen("1.yuv","w+");struct timeval start,end;while (camera.IsGrabbing())  {  // 等待接收和恢复图像,超时时间设置为5000 ms.camera.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);  //如果图像抓取成功if (ptrGrabResult->GrabSucceeded())  {  // 获取图像数据int m_width=ptrGrabResult->GetWidth();int m_height=ptrGrabResult->GetHeight();cout <<"SizeX: "<<m_width<<endl;  cout <<"SizeY: "<<m_height<<endl;  //将抓取的缓冲数据转化成pylon image.formatConverter.Convert(pylonImage, ptrGrabResult);  // 将 pylon image转成OpenCV image.//openCvImage = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t *) pylonImage.GetBuffer());//cvtColor(openCvImage,dst_image,CV_RGB2RGBA);#if 0unsigned long long timeusd=0;gettimeofday(&start,NULL);cvtColor(openCvImage,dst_image,CV_BGR2YUV_I420);gettimeofday(&end,NULL);//timeusd=end.tv_sec-start.tv_sec+(end.tv_usec-start.tv_usec)/1000000;cout<<"convert cost "<<end.tv_sec-start.tv_sec+(end.tv_usec-start.tv_usec)/1000000<< " sec"<<endl<<endl;#endif#if 1if(!I420Buffer){if(CUDA_FAILED(cudaMalloc((void**)&I420Buffer,m_height*m_width*3/2))){cout<<"cudaMalloc For I420Buffer Error"<<endl;}}#endif#if 1if(!RGBBuffer){if(CUDA_FAILED(cudaMalloc((void**)&RGBBuffer,m_height*m_width*3))){cout<<"cudaMalloc For RGBBuffer Error"<<endl;}}#endif#if 1if(!BGRABuffer){if(CUDA_FAILED(cudaMalloc((void**)&BGRABuffer,m_height*m_width*4))){cout<<"cudaMalloc For BGRABuffer Error"<<endl;}       }#endifcudaMemcpy(RGBBuffer,pylonImage.GetBuffer(),m_height*m_width*3,cudaMemcpyHostToDevice);#if 1if(CUDA_FAILED(cudaRGBToRGBAf((uchar3 *)RGBBuffer,(float4 *)BGRABuffer, m_width,m_height))){cout<<"Failed to Convert RGB2RGBA"<<endl;}#endif#if 1//cudaMemcpy(BGRABuffer,dst_image.data,m_height*m_width*4,cudaMemcpyHostToDevice);if(CUDA_FAILED(cudaRGBAToI420((uchar4 *)BGRABuffer,I420Buffer,m_width,m_height))){cout<<"Failed to Convert RGBAToI420"<<endl;     }#endifunsigned char g_buffer[m_height*m_width*3/2];#if 1cudaMemcpy(g_buffer,I420Buffer,m_width*m_height*3/2,cudaMemcpyDeviceToHost);fwrite(g_buffer,2448*2048*3/2,1,fp);#endif//如果需要保存图片if (saveImages)  {  std::ostringstream s;              // 按索引定义文件名存储图片s << "image_" << grabbedlmages << ".jpg";  std::string imageName(s.str());  //保存OpenCV image.cv::imwrite(imageName, openCvImage);  grabbedlmages++;  }  //如果需要记录视频if (recordVideo)  {  cvVideoCreator.write(openCvImage);  }  //新建OpenCV display window.//cv::namedWindow("OpenCV Display Window", CV_WINDOW_NORMAL); // other options: CV_AUTOSIZE, CV_FREERATIO//显示及时影像.//cv::imshow("OpenCV Display Window", dst_image);// Define a timeout for customer's input in// '0' means indefinite, i.e. the next image will be displayed after closing the window.// '1' means live streamwaitKey(1);  }  }  fclose(fp); }  catch (GenICam::GenericException &e)  {  // Error handling.cerr << "An exception occurred." << endl  << e.GetDescription() << endl;  }  return exitCode;
}

转换完成,加入编码推流的代码,推流是利用EasyDarwin做流媒体转发服务器:

// Grab.cpp
/*Note: Before getting started, Basler recommends reading the Programmer's Guide topicin the pylon C++ API documentation that gets installed with pylon.If you are upgrading to a higher major version of pylon, Basler alsostrongly recommends reading the Migration topic in the pylon C++ API documentation.This sample illustrates how to grab and process images using the CInstantCamera class.The images are grabbed and processed asynchronously, i.e.,while the application is processing a buffer, the acquisition of the next buffer is donein parallel.The CInstantCamera class uses a pool of buffers to retrieve image datafrom the camera device. Once a buffer is filled and ready,the buffer can be retrieved from the camera object for processing. The bufferand additional image data are collected in a grab result. The grab result isheld by a smart pointer after retrieval. The buffer is automatically reusedwhen explicitly released or when the smart pointer object is destroyed.
*/// Include files to use the PYLON API.//gst_rtsp#include "stdio.h"
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <signal.h>
#include <errno.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>  /* for TCP_NODELAY  */
#include <arpa/inet.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <pthread.h>
#include <sched.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
#include <fcntl.h>
#include <semaphore.h>
#include <net/if.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/vfs.h>
#include <pthread.h>
#include "assert.h"
#include <netdb.h>
#include <malloc.h>#include <deque>
#include <list>
#include <string>#include <stdio.h>
#include <signal.h>
#include <unistd.h>#include "video_encode.h"#include "libRtspPusherAPI.h"#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
#    include <pylon/PylonGUI.h>
#endif
#include"opencv2/opencv.hpp"
#include"opencv2/highgui.hpp"#include<sys/time.h>
#include"opencv2/core/core.hpp"
#include <pylon/gige/BaslerGigECamera.h>//定义是否保存图片 0-否 1-是
#define saveImages 0
//定义是否记录视频 0-否 1-是
#define recordVideo 0// Namespace for using pylon objects.
using namespace Pylon;// Namespace for using cout.
using namespace std;
#include "opencv2/gpu/gpu.hpp"using namespace cv;
// Number of images to be grabbed.
static const uint32_t c_countOfImagesToGrab = 1000000;bool signal_recieved = false;static int m_Width=0;
static int m_Height=0;void sig_handler(int signo)
{if( signo == SIGINT ){printf("received SIGINT\n");signal_recieved = true;}
}#define TEST_CHANNEL_NUM              5        // ����ͨ����
#define TEST_URL_MAX_LEN              128      // URL ��?�
#define TEST_LOOP_MAX_NUM             1000000  // ��������ѭ����
#define TEST_SINGLE_LOOP_TIME         30       // ����ѭ��ʱ��typedef struct {char pullStreamUrl[TEST_URL_MAX_LEN+1];char pushStreamRtspUrl[TEST_URL_MAX_LEN+1];int  pullStreamSuccess;void* rtspPushStreamHandle;
} TestChannelConfigure;#define TEST_CHANNEL_MAX_NUM          1        // ֧��ͨ�������TestChannelConfigure testChannelConfigure[TEST_CHANNEL_MAX_NUM] = {{"admin:buaa123456@rtsp://192.168.1.190","rtsp://192.168.5.43/110.sdp",0,NULL}
};#define  ENC_MAX_BUFFER   5sem_t sem_dec_output_read;
sem_t sem_dec_output_write;
pthread_mutex_t mutex;
void *g_buffer = NULL;
int  g_iReadBufferPos = 0;int encInput(unsigned char *Y, unsigned char *U, unsigned char*V, int *width, int *height, NvBuffer *buffer, void *pUserData)
{int i, j = 0;sem_wait(&sem_dec_output_read);pthread_mutex_lock(&mutex);for (i = 0; i < buffer->n_planes; i++){NvBuffer::NvBufferPlane &plane = buffer->planes[i];//NvBuffer::NvBufferPlane &plane_dec = User->m_buffer->planes[i];unsigned char *data = plane.data;unsigned int bytes_to_read =plane.fmt.bytesperpixel * plane.fmt.width;/*---DEBUG--[av_stream.cpp:  encInput: 2089]--[2017-07-01 07:12:45]--  encInput() channid[0] dec_buffer[1920 * 1080] buffer.n_planes[3]              plane.fmt.bytesperpixel[1] plane.fmt.width[1920] plane.fmt.height[1080]  plane.fmt.stride[2048] plane.bytesused[0]  ---DEBUG--[av_stream.cpp:  encInput: 2089]--[2017-07-01 07:12:45]--  encInput() channid[0] dec_buffer[1920 * 1080] buffer.n_planes[3]              plane.fmt.bytesperpixel[1] plane.fmt.width[960] plane.fmt.height[540]  plane.fmt.stride[1024] plane.bytesused[0]  ---DEBUG--[av_stream.cpp:  encInput: 2089]--[2017-07-01 07:12:45]--  encInput() channid[0] dec_buffer[1920 * 1080] buffer.n_planes[3]              plane.fmt.bytesperpixel[1] plane.fmt.width[960] plane.fmt.height[540]  plane.fmt.stride[1024] plane.bytesused[0]  */plane.bytesused = 0;for (j = 0; j < plane.fmt.height; j++){memcpy(data, (g_buffer + g_iReadBufferPos), bytes_to_read);data += plane.fmt.stride;g_iReadBufferPos += bytes_to_read;}plane.bytesused = plane.fmt.stride * plane.fmt.height;  printf( "i = [%d]  \nRes[%d*%d]  \nbytesperpixel[%d]  \nstride[%d] \nplane.bytesused[%d] \n", i, plane.fmt.width, plane.fmt.height, plane.fmt.bytesperpixel, plane.fmt.stride, plane.bytesused);}g_buffer = NULL;g_iReadBufferPos = 0;pthread_mutex_unlock(&mutex);sem_post(&sem_dec_output_write);return 0;
}FILE *fp4 = NULL;
int encOutput(char *pBuf, int iLen, void *pDataTypePara, void *pUserData)
{printf("............func:%s  Line:%d 0x%2x%2x%2x%2x%2x%2x %2x%2x%2x %2x%2x%2x iLen[%d]   \n", __func__, __LINE__, pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4], pBuf[5], pBuf[6], pBuf[7], pBuf[8], pBuf[9], pBuf[10], pBuf[11],iLen);
#if 0if (NULL == fp4){fp4 = fopen("out.264", "wb");int ret = fwrite(pBuf, 1, iLen, fp4);}else{int ret = fwrite(pBuf, 1, iLen, fp4);   }
#endif#if 1RTSP_Pusher_Handler rtspPushStreamHandle = testChannelConfigure[0].rtspPushStreamHandle;assert(testChannelConfigure != NULL);TmAVFrame avFrame;avFrame.frameType = VIDEO_FRAME_TYPE;avFrame.frameLen = iLen;avFrame.frameData = (unsigned char*)pBuf;//memcpy(avFrame.frameData,_pinBuf,avFrame.frameLen);int ret = RTSP_Pusher_PushFrame(rtspPushStreamHandle,&avFrame);if( ret < 0 ) {
#if 1printf("------------channel_%d push stream failed.\n",0);
#endif}
#endif}int enc_StatueCallBack(int ichannle, int statue, int iNowStreamFlag, void *pUserData)
{return 0;
}int RtspPushStreamLogCB(int logLevel,const char *logInfo,int len)
{printf("RtspPushStreamLogCB[%s] \n", logInfo);return 1;
}int RtspPushStreamStatueCB(RTSP_Pusher_Handler handler,RTSP_Pusher_State state, int statusCode, void *context)
{printf("RtspPushStreamStatueCB() state[%d]  statusCode[%d] \n", state, statusCode);return 1;
}/*void BGR_YUV420(unsigned char*bsrc,unsigned char *bdst,int width,int height)
{}*/
int main(int argc, char* argv[])
{// The exit code of the sample application.int exitCode = 0;if(argc!=2){std::cout<<"Usage: ./Grab0 rtsp://192.168.1.43(TX2_IP):554/110.sdp"<<endl;return -1;}
#if 1int ret;/*rtsp puser*/RTSP_Pusher_SetStartPort(50000);RTSP_Pusher_SetLogCallBack(RtspPushStreamLogCB);RTSP_Pusher_SetStreamStatusCallback(RtspPushStreamStatueCB, NULL);TmMediaInfo mediaInfo;RTSP_Pusher_Handler rtspPusherHandler = RTSP_Pusher_Create();assert(rtspPusherHandler != NULL);memset(&mediaInfo,0,sizeof(TmMediaInfo));mediaInfo.videoCodec = VIDEO_CODEC_H264;mediaInfo.videoFps   = 25;#if 0ret = RTSP_Pusher_StartStream(rtspPusherHandler,testChannelConfigure[0].pushStreamRtspUrl,RTP_OVER_UDP,NULL,NULL,0,&mediaInfo);#endifmemset(testChannelConfigure[0].pushStreamRtspUrl,0,sizeof(testChannelConfigure[0].pushStreamRtspUrl));strcpy(testChannelConfigure[0].pushStreamRtspUrl,argv[1]);ret = RTSP_Pusher_StartStream(rtspPusherHandler,testChannelConfigure[0].pushStreamRtspUrl,RTP_OVER_UDP,NULL,NULL,0,&mediaInfo);                    if(ret < 0 ) {printf("fun[%s] Line[%d] chId%d start push stream failed ret[%d].\n",__func__, __LINE__, 0, ret);return NULL;}testChannelConfigure[0].rtspPushStreamHandle = rtspPusherHandler;
#endifsem_init(&sem_dec_output_read, 0, 0);sem_init(&sem_dec_output_write, 0, 0);pthread_mutex_init(&mutex, NULL);g_buffer = NULL;g_iReadBufferPos = 0;TM_video_enc *enc_obj_merge;enc_context_t enc_cfg;//enc by TMenc_obj_merge = new TM_video_enc(0);if (NULL == enc_obj_merge){return 0;}enc_obj_merge->init(ENC_MAX_BUFFER);memset(&enc_cfg, 0, sizeof(enc_context_t));enc_cfg.ratecontrol = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR;enc_cfg.iframe_interval = 25;enc_cfg.idr_interval = 25;enc_cfg.level = V4L2_MPEG_VIDEO_H264_LEVEL_5_1;enc_cfg.fps_n = 25;enc_cfg.fps_d = 1;enc_cfg.num_b_frames = (uint32_t) -1;enc_cfg.nMinQpI = (uint32_t)QP_RETAIN_VAL;enc_cfg.nMaxQpI = (uint32_t)QP_RETAIN_VAL;enc_cfg.nMinQpP = (uint32_t)QP_RETAIN_VAL;enc_cfg.nMaxQpP = (uint32_t)QP_RETAIN_VAL;enc_cfg.nMinQpB = (uint32_t)QP_RETAIN_VAL;enc_cfg.nMaxQpB = (uint32_t)QP_RETAIN_VAL;enc_cfg.in_file_path = "tmp.yuv";enc_cfg.out_file_path = "tmp.h264";if (0/*VIDEO_CODEC_H265 == m_strChannelEncCfg.VideoEncodeType*/){enc_cfg.profile = V4L2_MPEG_VIDEO_H265_PROFILE_MAIN10;enc_cfg.encoder_pixfmt = V4L2_PIX_FMT_H265;}else{enc_cfg.level = V4L2_MPEG_VIDEO_H264_LEVEL_5_0;/*����Dz������ѹ���������iframe_interval Ҫ50���ϣ�����profile �ij�HIGH*/enc_cfg.profile = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN;/*����ij�HIGH �?��¼��elecard ���Ų���*/enc_cfg.encoder_pixfmt = V4L2_PIX_FMT_H264;}/*create v4l2 enc*///Pylon::PylonAutoInitTerm autoInitTerm;  try  {  //创建相机对象(以最先识别的相机)CTlFactory& tlFactory = CTlFactory::GetInstance();// Get all attached devices and exit application if// two cameras aren't foundDeviceInfoList_t devices;CInstantCamera camera;if( tlFactory.EnumerateDevices(devices) == 2 ){cout << "Found " << devices.size() << " cameras." << endl;camera.Attach(tlFactory.CreateDevice( devices[0] ) );if(camera.GetDeviceInfo().GetModelName()=="ML500-35C"){// 打印相机的名称std::cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl; camera.Open();}else{// 打印相机的名称std::cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl; camera.Open();}}else{camera.Attach(tlFactory.CreateDevice( devices[0]));camera.Open(); }  GenApi::INodeMap& nodemap = camera.GetNodeMap();  //打开相机//获取相机成像宽度和高度GenApi::CIntegerPtr width = nodemap.GetNode("Width");  GenApi::CIntegerPtr height = nodemap.GetNode("Height");  enc_cfg.width =(int)width->GetValue() /* * g_FaceScaleFactor*/;enc_cfg.height =(int)height->GetValue() /* * g_FaceScaleFactor*/;enc_cfg.insert_sps_pps_at_idr = true;/*ǿ��ÿһ��I֡ǰ����SPS PPS*/enc_cfg.iframe_interval = 25;enc_cfg.idr_interval = 25;enc_cfg.fps_n = 25;enc_cfg.bitrate =  2048 * 1024;void *pUser = (void *)"c++  duixiang ";enc_obj_merge->set_config(&enc_cfg, encInput, encOutput, enc_StatueCallBack, (void *)pUser);enc_obj_merge->start();//设置相机最大缓冲区,默认为10camera.MaxNumBuffer = 5;  // 新建pylon ImageFormatConverter对象.CImageFormatConverter formatConverter;  //确定输出像素格式formatConverter.OutputPixelFormat = PixelType_BGR8packed;  // 创建一个Pylonlmage后续将用来创建OpenCV imagesCPylonImage pylonImage;  //声明一个整形变量用来计数抓取的图像,以及创建文件名索引int grabbedlmages = 0;  // 新建一个OpenCV video creator对象.VideoWriter cvVideoCreator;  //新建一个OpenCV image对象.Mat openCvImage;  Mat dst_image;// 视频文件名std::string videoFileName = "openCvVideo.avi";  // 定义视频帧大小cv::Size frameSize = Size((int)width->GetValue(), (int)height->GetValue());  //设置视频编码类型和帧率,有三种选择// 帧率必须小于等于相机成像帧率cvVideoCreator.open(videoFileName, CV_FOURCC('D', 'I', 'V','X'), 10, frameSize, true);  //cvVideoCreator.open(videoFileName, CV_F0URCC('M','P',,4','2’), 20, frameSize, true);//cvVideoCreator.open(videoFileName, CV_FOURCC('M', '3', 'P', 'G'), 20, frameSize, true);// 开始抓取c_countOfImagesToGrab images.//相机默认设置连续抓取模式camera.StartGrabbing(c_countOfImagesToGrab, GrabStrategy_LatestImageOnly);  //抓取结果数据指针CGrabResultPtr ptrGrabResult;  // 当c_countOfImagesToGrab images获取恢复成功时,Camera.StopGrabbing()//被RetrieveResult()方法自动调用停止抓取unsigned long  timeusd=0;FILE *fp=fopen("1.yuv","w+");struct timeval start,end;while (camera.IsGrabbing())  {  // 等待接收和恢复图像,超时时间设置为5000 ms.camera.RetrieveResult(5000, ptrGrabResult, TimeoutHandling_ThrowException);  //如果图像抓取成功if (ptrGrabResult->GrabSucceeded())  {  // 获取图像数据cout <<"SizeX: "<<ptrGrabResult->GetWidth()<<endl;  cout <<"SizeY: "<<ptrGrabResult->GetHeight()<<endl;  //将抓取的缓冲数据转化成pylon image.formatConverter.Convert(pylonImage, ptrGrabResult);  // 将 pylon image转成OpenCV image.openCvImage = cv::Mat(ptrGrabResult->GetHeight(), ptrGrabResult->GetWidth(), CV_8UC3, (uint8_t *) pylonImage.GetBuffer());  gettimeofday(&start,NULL);cvtColor(openCvImage,dst_image,CV_BGR2YUV_I420);gettimeofday(&end,NULL);pthread_mutex_lock(&mutex);g_buffer = dst_image.data;g_iReadBufferPos = 0;pthread_mutex_unlock(&mutex);sem_post(&sem_dec_output_read);sem_wait(&sem_dec_output_write);timeusd=start.tv_sec-end.tv_sec+(start.tv_usec-end.tv_usec)/1000000;//imshow("test",dst_image);//如果需要保存图片if (saveImages)  {  std::ostringstream s;              // 按索引定义文件名存储图片s << "image_" << grabbedlmages << ".jpg";  std::string imageName(s.str());  //保存OpenCV image.cv::imwrite(imageName, openCvImage);  grabbedlmages++;  }  //如果需要记录视频if (recordVideo)  {  cvVideoCreator.write(openCvImage);  }  //新建OpenCV display window.//cv::namedWindow("OpenCV Display Window", CV_WINDOW_NORMAL); // other options: CV_AUTOSIZE, CV_FREERATIO//显示及时影像.//cv::imshow("OpenCV Display Window", dst_image);// Define a timeout for customer's input in// '0' means indefinite, i.e. the next image will be displayed after closing the window.// '1' means live streamwaitKey(1);  }  }  }  catch (GenICam::GenericException &e)  {  // Error handling.cerr << "An exception occurred." << endl  << e.GetDescription() << endl;  }  return exitCode;
}  

基于NVIDIA TX2的usb basyer工业相机编码推流相关推荐

  1. 天瞳威视基于NVIDIA TX2的ADAS方案

    目前,天瞳威视ADAS系统CalmCar能够实现的功能包括LDW(车道偏离预警.).FCW(前向碰撞预警).PCA(行人碰撞预警).BSD(盲区监测).TSR(交通标志识别).这一切,都是通过一枚单目 ...

  2. NVIDIA TX2 使用 USB 摄像头

    用了一个很冷门的 USB 摄像头,在 Windows 下会自动安装驱动,本来以为在 Ubuntu 下得手动安,试了 easycam 和 gspca 都失败(太老了).没想到貌似根本不需要安装,TX2 ...

  3. 环宇智行基于NVIDIA TX2的L4级自动驾驶方案

    参考: http://www.in-driving.com/product/showproduct.php?lang=cn&id=54#ad-image-0 http://zhidx.com/ ...

  4. Nvidia TX2+rplidar+autolabor pro1实现自主导航机器人

    简介 程序实现了室内自主导航机器人.基本功能有激光SLAM建图.AMCL定位.机器人运动规划.车辆监控和任务规划. 底盘采用Autolabor公司的autolabor pro1,激光雷达选用rplid ...

  5. 嵌入式linux作为hid设备,基于嵌入式系统的USB(HID)设备

    基于嵌入式系统的USB(HID)设备 目前嵌入式系统在数字化电子产品领域应用越来越广泛.随着其成本的降低,大有取代单片机的趋势. USB设备以其小巧.便携.即插即用.成本低廉等优势在当前的桌面应用中有 ...

  6. 基于NVIDIA Xavier NX(ubuntu20.04)的Optitrack视觉定位 PX4+ros noetic(实物运行记录)

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一:硬件准备 两种界面化显示的方式 无线连接 有线连接 二:软件准备 1:远程登录软件 NoMachine 2:安装r ...

  7. NVIDIA TX2刷ubuntu16.04、刷设备树教程

    实验室自制的板子上使用gpu ,有的USB口不一定能使用:  tx1可以直接用,tx2且是16.04系统的,可以刷设备树文件解决,tx2i以及18.04系统的我找不到设备树文件.这也是为啥我会把18. ...

  8. 基于NVIDIA GPUs的深度学习训练新优化

    基于NVIDIA GPUs的深度学习训练新优化 New Optimizations To Accelerate Deep Learning Training on NVIDIA GPUs 不同行业采用 ...

  9. 基于主观感兴趣区域的视频编码实践

    本文由芒果TV音视频技术专家谭嵩在LiveVideoStackCon2020线上峰会的演讲内容整理而成,结合芒果TV的工程化研发实践经验,对基于主观感兴趣区域的视频编码技术进行了详细解析. 文 / 谭 ...

最新文章

  1. 简释iptables防火墙
  2. windows10安装Oracle提示错误-INS-13001环境不满足最低要求
  3. python一些常用函数_【python】常用的一些内置函数
  4. docker desktop ubuntu镜像_原创 | Docker入门,看了不理解,假一赔命
  5. Django中form字段操作
  6. Java开发 基础三十条 初学必看
  7. edg击败we视频_德玛西亚杯八强淘汰赛EDG战胜WE比赛视频回看_完整版视频高清观看...
  8. Maven 自问自答
  9. 微信小程序开发-微信支付功能【WxMaService 获取openid,WxPayService建微信订单,接收微信支付异步通知回调方法,附有完整前后端代码】
  10. 移动应用测试与PC端测试区别
  11. win7企业版安装vmtool提示无法进行,需要更新到SP1。【不换镜像,已解决】
  12. [JAVA][正则表达式]
  13. 测试领域的大佬博客(个人收藏向)
  14. 什么是ui设计培训?ui培训课程难学吗?
  15. Python读取上证指数csv
  16. 房东妹子青春期听译练习稿
  17. 《底层逻辑》读书笔记
  18. 轻松上手UAI-Train,拍拍贷人脸识别算法优化效率提升85.7%
  19. win10自带看图工具不见,修改注册表就出来了
  20. 1221 打印字母菱形图案

热门文章

  1. 自用笔记-Qt5.14.2开发Android环境搭建
  2. 西邮Linux兴趣小组2019面试题总结
  3. 101条伟大的计算机编程名言 [ROYcms!NT]
  4. Debian配置ssh服务
  5. 对于国内计算机代数计算发展的一些看法
  6. 华硕的笔记本为什么按Fn+F9禁用触摸板不起作用了?
  7. tencent腾讯——面试
  8. 人工智能新标准丨Whale 帷幄参与制定,助力信息安全产业建设
  9. python 实现股票MACD计算
  10. UNIX Crom 任务调度配置语法