Skip to content

Commit

Permalink
Switch to MSVC2017 compiled openCV. Enable additional video codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
daharoni committed Jan 18, 2020
1 parent 3fe35ca commit b363d9c
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 39 deletions.
42 changes: 25 additions & 17 deletions Miniscope-DAQ-QT-Software.pro
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,27 @@ QML_IMPORT_PATH =
# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

INCLUDEPATH += C:\opencv-build\install\include
#Below is for the opencv build I did
#INCLUDEPATH += C:\opencv-build\install\include


LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_core412.dll.a
LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_highgui412.dll.a
LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgcodecs412.dll.a
LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412.dll.a
LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_features2d412.dll.a
LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_calib3d412.dll.a
LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412.dll.a
LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_videoio412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_core412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_highgui412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgcodecs412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_features2d412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_calib3d412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_videoio412.dll.a

#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_core412d.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_highgui412d.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgcodecs412d.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412d.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_features2d412d.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_calib3d412d.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412d.dll.a
#LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_videoio412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_core412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_highgui412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgcodecs412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_features2d412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_calib3d412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_imgproc412d.dll.a
##LIBS += C:\opencv-build\install\x64\mingw\lib\libopencv_videoio412d.dll.a


# Default rules for deployment.
Expand All @@ -72,3 +73,10 @@ HEADERS += \
videostreamocv.h

DISTFILES +=


win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../../../opencv-build420/install/x64/vc15/lib/ -lopencv_world420
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../../../opencv-build420/install/x64/vc15/lib/ -lopencv_world420d

INCLUDEPATH += $$PWD/../../../../../../opencv-build420/install/include
DEPENDPATH += $$PWD/../../../../../../opencv-build420/install/include
4 changes: 3 additions & 1 deletion backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "datasaver.h"
#include "behaviortracker.h"

#define DEBUG
//#define DEBUG

backEnd::backEnd(QObject *parent) :
QObject(parent),
Expand Down Expand Up @@ -162,6 +162,7 @@ void backEnd::setupDataSaver()
// dataSaver->startRecording();

for (int i = 0; i < miniscope.length(); i++) {
dataSaver->setDataCompression(miniscope[i]->getDeviceName(), miniscope[i]->getCompressionType());
dataSaver->setFrameBufferParameters(miniscope[i]->getDeviceName(),
miniscope[i]->getFrameBufferPointer(),
miniscope[i]->getTimeStampBufferPointer(),
Expand All @@ -174,6 +175,7 @@ void backEnd::setupDataSaver()
dataSaver->setHeadOrientationStreamingState(miniscope[i]->getDeviceName(), miniscope[i]->getHeadOrienataionStreamState());
}
for (int i = 0; i < behavCam.length(); i++) {
dataSaver->setDataCompression(behavCam[i]->getDeviceName(), behavCam[i]->getCompressionType());
dataSaver->setFrameBufferParameters(behavCam[i]->getDeviceName(),
behavCam[i]->getFrameBufferPointer(),
behavCam[i]->getTimeStampBufferPointer(),
Expand Down
6 changes: 6 additions & 0 deletions behaviorcam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ void BehaviorCam::connectSnS(){
void BehaviorCam::parseUserConfigBehavCam() {
// Currently not needed. If arrays get added into JSON config then this might
m_deviceName = m_ucBehavCam["deviceName"].toString("Behavior Cam " + QString::number(m_ucBehavCam["deviceID"].toInt()));
m_compressionType = m_ucBehavCam["compression"].toString("None");
}

QString BehaviorCam::getCompressionType()
{
return m_compressionType;
}

//void BehaviorCam::sendInitCommands()
Expand Down
2 changes: 2 additions & 0 deletions behaviorcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BehaviorCam : public QObject
void createView();
void connectSnS();
void parseUserConfigBehavCam();
QString getCompressionType();
// void sendInitCommands();
cv::Mat* getFrameBufferPointer(){return frameBuffer;}
qint64* getTimeStampBufferPointer(){return timeStampBuffer;}
Expand Down Expand Up @@ -90,6 +91,7 @@ public slots:
// QMap<QString, int> m_sendCommand;

bool m_streamHeadOrientationState;
QString m_compressionType;
};

#endif // BEHAVIORCAM_H
26 changes: 25 additions & 1 deletion datasaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void DataSaver::startRunning()
isColor = true;
// TODO: Add compression options here
videoWriter[names[i]]->open(tempStr.toUtf8().constData(),
cv::VideoWriter::fourcc('M','J','P','G'), 60,
dataCompressionFourCC[names[i]], 60,
cv::Size(frameBuffer[names[i]][0].cols, frameBuffer[names[i]][0].rows), isColor); // color should be set to false?

}
Expand Down Expand Up @@ -289,6 +289,30 @@ void DataSaver::takeNote(QString note)
}
}

void DataSaver::setDataCompression(QString name, QString type)
{
if (type == "MJPG")
dataCompressionFourCC[name] = cv::VideoWriter::fourcc('M','J','P','G');
// else if (type == "uncompressed" || type == "None")
// dataCompressionFourCC[name] = cv::VideoWriter::fourcc('D','I','B',' ');
else if (type == "MJ2C")
dataCompressionFourCC[name] = cv::VideoWriter::fourcc('M','J','2','C');
else if (type == "XVID")
dataCompressionFourCC[name] = cv::VideoWriter::fourcc('X','V','I','D');
else if (type == "FFV1")
dataCompressionFourCC[name] = cv::VideoWriter::fourcc('F','F','V','1');
// else if (type == "LAGS")
// dataCompressionFourCC[name] = cv::VideoWriter::fourcc('L','A',G','S');
else
dataCompressionFourCC[name] = cv::VideoWriter::fourcc('F','F','V','1');

qDebug() << name << type << dataCompressionFourCC[name];

// cv::VideoWriter test;
// test.open("hi.avi",-1,30,cv::Size(100,100));

}

QJsonDocument DataSaver::constructBaseDirectoryMetaData()
{
QJsonObject metaData;
Expand Down
2 changes: 2 additions & 0 deletions datasaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public slots:
void devicePropertyChanged(QString deviceName, QString propName, QVariant propValue);
void takeScreenShot(QString type);
void takeNote(QString note);
void setDataCompression(QString name, QString type);

private:
QJsonDocument constructBaseDirectoryMetaData();
Expand All @@ -66,6 +67,7 @@ public slots:
QMap<QString, QSemaphore*> freeCount;
QMap<QString, QSemaphore*> usedCount;
QMap<QString, cv::VideoWriter*> videoWriter;
QMap<QString, int> dataCompressionFourCC;

QMap<QString, QFile*> csvFile;
QMap<QString, QTextStream*> csvStream;
Expand Down
6 changes: 6 additions & 0 deletions miniscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void Miniscope::connectSnS(){
void Miniscope::parseUserConfigMiniscope() {
// Currently not needed. If arrays get added into JSON config then this might
m_deviceName = m_ucMiniscope["deviceName"].toString("Miniscope " + QString::number(m_ucMiniscope["deviceID"].toInt()));
m_compressionType = m_ucMiniscope["compression"].toString("None");
}

void Miniscope::sendInitCommands()
Expand Down Expand Up @@ -183,6 +184,11 @@ void Miniscope::sendInitCommands()
}
}

QString Miniscope::getCompressionType()
{
return m_compressionType;
}

void Miniscope::getMiniscopeConfig(QString deviceType) {
QString jsonFile;
QFile file;
Expand Down
2 changes: 2 additions & 0 deletions miniscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Miniscope : public QObject
void connectSnS();
void parseUserConfigMiniscope();
void sendInitCommands();
QString getCompressionType();
cv::Mat* getFrameBufferPointer(){return frameBuffer;}
qint64* getTimeStampBufferPointer(){return timeStampBuffer;}
float* getBNOBufferPointer() { return bnoBuffer; }
Expand Down Expand Up @@ -103,6 +104,7 @@ public slots:
QMap<QString, int> m_sendCommand;

bool m_streamHeadOrientationState;
QString m_compressionType;

};

Expand Down
22 changes: 5 additions & 17 deletions userConfigs/UserConfigExample.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"imageRegistration": "Off",
"streamHeadOrientation": true,
"deviceID": 1,
"compressionOptions": ["None","MJPG"],
"compression": "Not implemented yet",
"compressionOptions": ["MJPG","MJ2C","XVID","FFV1"],
"compression": "FFV1",
"framesPerFile": 1000,
"windowScale": 0.75,
"windowX": 800,
Expand All @@ -42,26 +42,14 @@
"frameRate": "30FPS"
}
],
"cameras2": [
"cameras": [
{
"deviceName": "BehavCam 0",
"deviceType": "WebCam",
"deviceID": 0,
"cameraCalibrationFileLocation": "",
"compressionOptions": ["None","MJPG"],
"compression": "Not implemented yet",
"framesPerFile": 1000,
"windowScale": 0.75,
"windowX": 800,
"windowY": 600
},
{
"deviceName": "BehavCam 1",
"deviceType": "WebCam",
"deviceID": 1,
"cameraCalibrationFileLocation": "",
"compressionOptions": ["None","MJPG"],
"compression": "Not implemented yet",
"compressionOptions": ["MJPG","MJ2C","XVID","FFV1"],
"compression": "FFV1",
"framesPerFile": 1000,
"windowScale": 0.75,
"windowX": 800,
Expand Down
6 changes: 3 additions & 3 deletions videostreamocv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ VideoStreamOCV::~VideoStreamOCV() {
int VideoStreamOCV::connect2Camera(int cameraID) {
m_cameraID = cameraID;
cam = new cv::VideoCapture;
cam->open(m_cameraID);
// qDebug() << "Camera capture backend is" << QString::fromStdString (cam->getBackendName());
cam->open(m_cameraID, cv::CAP_DSHOW);
qDebug() << "Camera capture backend is" << QString::fromStdString (cam->getBackendName());
return cam->isOpened();


Expand All @@ -56,7 +56,7 @@ void VideoStreamOCV::startStream()
int idx = 0;
int daqFrameNumOffset = 0;
// float heading, pitch, roll;
double w, x, y, z, norm;
double w, x, y, z;
cv::Mat frame;

m_stopStreaming = false;
Expand Down

0 comments on commit b363d9c

Please sign in to comment.