Browse Source

add driver_jpg2mp4

yuchuli 3 years ago
parent
commit
5df034d6d9

+ 73 - 0
src/driver/driver_jpg2mp4/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 35 - 0
src/driver/driver_jpg2mp4/driver_jpg2mp4.pro

@@ -0,0 +1,35 @@
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += main.cpp \
+    ../../include/msgtype/rawpic.pb.cc
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivopencv.pri ) {
+    error( "Couldn't find the ivopencv.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+
+}
+
+
+HEADERS += \
+    ../../include/msgtype/rawpic.pb.h

+ 89 - 0
src/driver/driver_jpg2mp4/main.cpp

@@ -0,0 +1,89 @@
+#include <QCoreApplication>
+
+#include <iostream>
+
+#include "modulecomm.h"
+
+
+#include "rawpic.pb.h"
+
+#include "opencv2/video.hpp"
+#include "opencv2/videoio.hpp"
+
+#include <opencv2/opencv.hpp>
+#include <opencv2/core.hpp>
+
+//#ifdef NVIDIA_AGX
+#include <opencv2/imgcodecs/legacy/constants_c.h>    //OpenCV4 use this line
+#include <opencv2/imgproc/types_c.h>   //OpenCV4 use this line
+//#endif
+
+cv::VideoWriter mWriter;
+
+bool mbSave = true;
+
+void encode(iv::vision::rawpic & xrawpic)
+{
+    std::cout<<"jpg size : "<<xrawpic.picdata().size()<<std::endl;
+
+    cv::Mat mat(xrawpic.height(),xrawpic.width(),xrawpic.mattype());
+
+    if(mbSave)
+    {
+        if(xrawpic.type() == 1)
+            memcpy(mat.data,xrawpic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
+        else
+        {
+            std::vector<unsigned char> buff(xrawpic.picdata().data(),xrawpic.picdata().data()+xrawpic.picdata().size());
+            mat = cv::imdecode(buff,CV_LOAD_IMAGE_COLOR);
+        }
+        int font = cv::FONT_HERSHEY_DUPLEX;
+        QDateTime xrecvtime = QDateTime::fromMSecsSinceEpoch(xrawpic.time());
+ //       char strtext[256];
+  //      snprintf(strtext,"%s",xrecvtime.toString("yyyy-MM-dd hh:mm:ss:zzz").toLatin1().data());
+        std::string strtext = xrecvtime.toString("yyyy-MM-dd hh:mm:ss:zzz").toStdString();
+        double fratio = xrawpic.width()/640;
+        int fontsize = 0.5*fratio;
+        if(fontsize<1)fontsize = 1;
+        cv::putText(mat,strtext,cv::Point(xrawpic.width() - 230*fratio,30*fratio),font,0.5*fratio,cv::Scalar(0,255,0),fontsize);
+  //      cv::putText(mat,mstrvin,cv::Point(10,30*fratio),font,0.5*fratio,cv::Scalar(0,255,0),fontsize);
+
+    }
+    static int ncount = 0;
+    ncount++;
+    if(ncount<11)
+    {
+        QTime xTime;
+        xTime.start();
+        mWriter<<mat;
+        std::cout<<"comp time :"<<xTime.elapsed()<<std::endl;
+    }
+    if(ncount == 11)
+    {
+        mWriter.release();
+    }
+
+    return;
+}
+
+
+void ListenPicData(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
+{
+    iv::vision::rawpic xrawpic;
+    if(xrawpic.ParseFromArray(strdata,nSize))
+    {
+        encode(xrawpic);
+    }
+}
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+    mWriter.open("/home/nvidia/testcv.mkv",cv::VideoWriter::fourcc('M','P','4','2'),30.0,cv::Size(1920,1080),1);
+
+    void * pa = iv::modulecomm::RegisterRecv("picfront",ListenPicData);
+
+    return a.exec();
+
+}