22 Commits

Author SHA1 Message Date
e4a7c4481b 打印版本号 2023-07-14 16:34:31 +08:00
1476c2bc15 内存映射mremap在320G时会失败,改为用fwrite,经测试980PRO 2个bin1 采集80分钟不会丢帧; 2023-07-14 16:33:37 +08:00
6d6b662cec 输出调试信息 2023-07-14 09:21:58 +08:00
2e158431e7 输出版本号:35 2023-07-04 21:23:25 +08:00
6473a1f4ce 内存映射写磁盘 2023-07-04 21:22:38 +08:00
cc76d62ded 1. 使用相机时间来计算times文件;
2. times放弃每帧写一次的方法;
3. 不满100帧的内容不丢弃:添加一个队列来记录压入队列的帧数;
2023-06-30 15:21:23 +08:00
e620c87ecf 打印版本号 2023-06-28 13:32:59 +08:00
47002ad894 改变光谱bin2的波长计算方式为:通过bin1平均相邻波长获取; 2023-06-28 11:59:46 +08:00
5337a40837 更新:发送 bin 状态到遥控器 2023-06-27 14:01:19 +08:00
6b78db5bc3 改变写线程退出方式,不再等待一段时间; 2023-06-25 21:20:45 +08:00
73f9b00b02 修改写线程总等待时间为:4275ms 2023-06-25 18:28:43 +08:00
6fc2680a1c 1. 配置文件:ximeadll加入 getBufferPolicy 和 getAcqBufferSize;
2. 增大内存池的大小,以便100帧写一次硬盘;
3. 增加ximea报错代码:10/11,将报错代码添加时间写入文件;
2023-06-21 16:43:33 +08:00
09d224075a 1. 通过sock发送设置成功的帧率;
2. 通过sock发送设置成功的曝光时间和曝光时最大的像素值;
2023-05-24 16:38:10 +08:00
371c422a34 1. 错误控制;
2. 创建配置文件的文件夹;
2023-04-10 15:54:57 +08:00
b31cd5fc8a 1、关闭影像文件句柄;
2、将sbg文件后缀从sbg改为bin;
2023-04-03 13:17:56 +08:00
447a1aafb1 1. 最大曝光时间乘以0.95,目的:避免曝光时间超过最大,而造成帧率降低;
2. 去掉多余的std::out,避免采集log过于杂乱;
3. 通过OpenCV从高光谱影像中提取rgb影像;
4. 在log中记录开始采集时间和停止采集时间;
5. 添加手动设置曝光时间的功能:127.0.0.1 7,2;
6. 头文件中写入仪器序列号;
2023-03-19 16:44:12 +08:00
e96953b54a 优化:
1. 通过内存池解决丢帧问题;
2. 解析惯导卫星个数,并通过socket发送给psdk;
3. 取消通过sbg卫星时间设置linux系统时间,此功能交给psdk做;
2022-12-24 16:59:41 +08:00
da57cc8e87 修补627f666提交没注意的曝光bug 2022-12-07 19:33:51 +08:00
cbff36447b 更改配置文件读写文件路径到:/media/nvme/300TC/config/ximea.cfg; 2022-12-06 14:50:18 +08:00
627f666d30 修改:
1. 写配置文件类修改:为了提高帧率 → 直接设置有效窗口,后期不进行roi裁剪;
2. 配合ximea采集类,修改写文件fwrite代码:
3. sbg新端口;
2022-11-22 23:23:32 +08:00
87a35f5dd4 新增 + 修改
1. 分离空间维(水平)和光谱维(垂直)的bin1和bin2有效窗口的参数:configfile.cpp和ximeaimager.cpp都需要修改相应代码;
2. 为了减少光谱仪的热量累积,加入了usb开电、断电功能,udpserver.cpp需要增加相应开电、断电代码:
3. 使用了云一峰的新板子,linux识别的惯导串口号改变:sbgrecorder.cpp;
2022-10-13 16:30:40 +08:00
374a48022b 修复路径问题
1. 配置文件创建在程序所在目录;
2. csv文件(ximea温度)输出路径改为:/home/programRunLog/hyperspectralLog;
2022-10-09 23:00:15 +08:00
17 changed files with 1509 additions and 207 deletions

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.idea .idea
build build
/温度测试
扩展板接口.txt

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.5.2)
project(ximeaAirborneSystem) project(ximeaAirborneSystem)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
@ -9,7 +9,7 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(QT Core Network SerialPort) set(QT Core Network SerialPort Gui)
set(TEMPLATE app) set(TEMPLATE app)
set(TARGET ximeaImageRecorder) set(TARGET ximeaImageRecorder)
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -17,9 +17,12 @@ find_package(Qt5 REQUIRED ${QT})#
include_directories(.) include_directories(.)
include_directories(/home/300tc/library/ximeaControlDll/Header_Files) include_directories(/home/300tc/library/ximeaControlDll/Header_Files)
link_directories(/home/300tc/library/ximeaControlDll) link_directories(/home/300tc/library/ximeaControlDll)
find_package(OpenCV 4.2.0 REQUIRED)
include_directories(/usr/local/include/opencv4/)
link_directories(/usr/local/lib)
add_executable(${CMAKE_PROJECT_NAME} add_executable(${CMAKE_PROJECT_NAME}
Source_Files/fileoperation.cpp Source_Files/fileoperation.cpp
Header_Files/fileoperation.h Header_Files/fileoperation.h
@ -41,10 +44,13 @@ add_executable(${CMAKE_PROJECT_NAME}
Source_Files/ximeaimager.cpp Source_Files/ximeaimager.cpp
Header_Files/ximeaimager.h Header_Files/ximeaimager.h
Source_Files/configfile.cpp Source_Files/configfile.cpp
Header_Files/configfile.h) Header_Files/configfile.h
Header_Files/MemoryPool.tcc
Header_Files/MemoryPool.h Source_Files/rgbImage.cpp Header_Files/rgbImage.h)
qt5_use_modules(${CMAKE_PROJECT_NAME} ${QT}) qt5_use_modules(${CMAKE_PROJECT_NAME} ${QT})
target_link_libraries(${CMAKE_PROJECT_NAME} target_link_libraries(${CMAKE_PROJECT_NAME}
irisXimeaImager irisXimeaImager
libconfig.so libconfig.so
libconfig++.so) libconfig++.so
${OpenCV_LIBS})

98
Header_Files/MemoryPool.h Normal file
View File

@ -0,0 +1,98 @@
/*-
* Copyright (c) 2013 Cosku Acay, http://www.coskuacay.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef MEMORY_POOL_H
#define MEMORY_POOL_H
#include <climits>
#include <cstddef>
template <typename T, size_t BlockSize = 409200000>
class MemoryPool
{
public:
/* Member types */
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef const T* const_pointer;
typedef const T& const_reference;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef std::false_type propagate_on_container_copy_assignment;
typedef std::true_type propagate_on_container_move_assignment;
typedef std::true_type propagate_on_container_swap;
template <typename U> struct rebind {
typedef MemoryPool<U> other;
};
/* Member functions */
MemoryPool() noexcept;
MemoryPool(const MemoryPool& memoryPool) noexcept;
MemoryPool(MemoryPool&& memoryPool) noexcept;
template <class U> MemoryPool(const MemoryPool<U>& memoryPool) noexcept;
~MemoryPool() noexcept;
MemoryPool& operator=(const MemoryPool& memoryPool) = delete;
MemoryPool& operator=(MemoryPool&& memoryPool) noexcept;
pointer address(reference x) const noexcept;
const_pointer address(const_reference x) const noexcept;
// Can only allocate one object at a time. n and hint are ignored
pointer allocate(size_type n = 1, const_pointer hint = 0);
void deallocate(pointer p, size_type n = 1);
size_type max_size() const noexcept;
template <class U, class... Args> void construct(U* p, Args&&... args);
template <class U> void destroy(U* p);
template <class... Args> pointer newElement(Args&&... args);
void deleteElement(pointer p);
private:
union Slot_ {
value_type element;
Slot_* next;
};
typedef char* data_pointer_;
typedef Slot_ slot_type_;
typedef Slot_* slot_pointer_;
slot_pointer_ currentBlock_;
slot_pointer_ currentSlot_;
slot_pointer_ lastSlot_;
slot_pointer_ freeSlots_;
size_type padPointer(data_pointer_ p, size_type align) const noexcept;
void allocateBlock();
static_assert(BlockSize >= 2 * sizeof(slot_type_), "BlockSize too small.");
};
#include "MemoryPool.tcc"
#endif // MEMORY_POOL_H

235
Header_Files/MemoryPool.tcc Normal file
View File

@ -0,0 +1,235 @@
/*-
* Copyright (c) 2013 Cosku Acay, http://www.coskuacay.com
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef MEMORY_BLOCK_TCC
#define MEMORY_BLOCK_TCC
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::size_type
MemoryPool<T, BlockSize>::padPointer(data_pointer_ p, size_type align)
const noexcept
{
uintptr_t result = reinterpret_cast<uintptr_t>(p);
return ((align - result) % align);
}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::MemoryPool()
noexcept
{
currentBlock_ = nullptr;
currentSlot_ = nullptr;
lastSlot_ = nullptr;
freeSlots_ = nullptr;
}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::MemoryPool(const MemoryPool& memoryPool)
noexcept :
MemoryPool()
{}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::MemoryPool(MemoryPool&& memoryPool)
noexcept
{
currentBlock_ = memoryPool.currentBlock_;
memoryPool.currentBlock_ = nullptr;
currentSlot_ = memoryPool.currentSlot_;
lastSlot_ = memoryPool.lastSlot_;
freeSlots_ = memoryPool.freeSlots;
}
template <typename T, size_t BlockSize>
template<class U>
MemoryPool<T, BlockSize>::MemoryPool(const MemoryPool<U>& memoryPool)
noexcept :
MemoryPool()
{}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>&
MemoryPool<T, BlockSize>::operator=(MemoryPool&& memoryPool)
noexcept
{
if (this != &memoryPool)
{
std::swap(currentBlock_, memoryPool.currentBlock_);
currentSlot_ = memoryPool.currentSlot_;
lastSlot_ = memoryPool.lastSlot_;
freeSlots_ = memoryPool.freeSlots;
}
return *this;
}
template <typename T, size_t BlockSize>
MemoryPool<T, BlockSize>::~MemoryPool()
noexcept
{
slot_pointer_ curr = currentBlock_;
while (curr != nullptr) {
slot_pointer_ prev = curr->next;
operator delete(reinterpret_cast<void*>(curr));
curr = prev;
}
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::pointer
MemoryPool<T, BlockSize>::address(reference x)
const noexcept
{
return &x;
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::const_pointer
MemoryPool<T, BlockSize>::address(const_reference x)
const noexcept
{
return &x;
}
template <typename T, size_t BlockSize>
void
MemoryPool<T, BlockSize>::allocateBlock()
{
// Allocate space for the new block and store a pointer to the previous one
data_pointer_ newBlock = reinterpret_cast<data_pointer_>
(operator new(BlockSize));
reinterpret_cast<slot_pointer_>(newBlock)->next = currentBlock_;
currentBlock_ = reinterpret_cast<slot_pointer_>(newBlock);
// Pad block body to staisfy the alignment requirements for elements
data_pointer_ body = newBlock + sizeof(slot_pointer_);
size_type bodyPadding = padPointer(body, alignof(slot_type_));
currentSlot_ = reinterpret_cast<slot_pointer_>(body + bodyPadding);
lastSlot_ = reinterpret_cast<slot_pointer_>
(newBlock + BlockSize - sizeof(slot_type_) + 1);
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::pointer
MemoryPool<T, BlockSize>::allocate(size_type n, const_pointer hint)
{
if (freeSlots_ != nullptr) {
pointer result = reinterpret_cast<pointer>(freeSlots_);
freeSlots_ = freeSlots_->next;
return result;
}
else {
if (currentSlot_ >= lastSlot_)
allocateBlock();
return reinterpret_cast<pointer>(currentSlot_++);
}
}
template <typename T, size_t BlockSize>
inline void
MemoryPool<T, BlockSize>::deallocate(pointer p, size_type n)
{
if (p != nullptr) {
reinterpret_cast<slot_pointer_>(p)->next = freeSlots_;
freeSlots_ = reinterpret_cast<slot_pointer_>(p);
}
}
template <typename T, size_t BlockSize>
inline typename MemoryPool<T, BlockSize>::size_type
MemoryPool<T, BlockSize>::max_size()
const noexcept
{
size_type maxBlocks = -1 / BlockSize;
return (BlockSize - sizeof(data_pointer_)) / sizeof(slot_type_) * maxBlocks;
}
template <typename T, size_t BlockSize>
template <class U, class... Args>
inline void
MemoryPool<T, BlockSize>::construct(U* p, Args&&... args)
{
new (p) U (std::forward<Args>(args)...);
}
template <typename T, size_t BlockSize>
template <class U>
inline void
MemoryPool<T, BlockSize>::destroy(U* p)
{
p->~U();
}
template <typename T, size_t BlockSize>
template <class... Args>
inline typename MemoryPool<T, BlockSize>::pointer
MemoryPool<T, BlockSize>::newElement(Args&&... args)
{
pointer result = allocate();
construct<value_type>(result, std::forward<Args>(args)...);
return result;
}
template <typename T, size_t BlockSize>
inline void
MemoryPool<T, BlockSize>::deleteElement(pointer p)
{
if (p != nullptr) {
p->~value_type();
deallocate(p);
}
}
#endif // MEMORY_BLOCK_TCC

View File

@ -9,9 +9,14 @@
#include <iomanip> #include <iomanip>
#include <cstdlib> #include <cstdlib>
#include <libconfig.h++> #include <libconfig.h++>
#include <string>
#include <QFileInfo> #include <QFileInfo>
#include <QString> #include <QString>
#include <QCoreApplication>
#include <QDir>
#include "utility_tc.h"
using namespace std; using namespace std;
using namespace libconfig; using namespace libconfig;
@ -25,10 +30,17 @@ public:
bool isConfigfileExist(); bool isConfigfileExist();
bool parseConfigfile(); bool parseConfigfile();
bool getBin(int &bin); bool getSpectralBin(int &spectralBin);
bool getspatialBin(int &spatialBin);
bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety); bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety);
bool getEffectiveWindowRoi(int &width, int &offsetx); bool getEffectiveWindowRoi(int &width, int &offsetx);
bool getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString);//spectralBinString = "bin1"或者”bin2“
bool getGainOffset(float &gain, float &offset); bool getGainOffset(float &gain, float &offset);
bool getGainOffsetOfSpectralBin1(float &gain, float &offset);
bool getSN(QString &SN);
bool getBufferPolicy(int &bufferPolicy);
bool getAcqBufferSize(int &acqBufferSize);
bool createConfigFile(); bool createConfigFile();
bool updateConfigFile(); bool updateConfigFile();

75
Header_Files/rgbImage.h Normal file
View File

@ -0,0 +1,75 @@
//
// Created by tangchao on 2022/12/24.
//
#ifndef XIMEAAIRBORNESYSTEM_RGBIMAGE_H
#define XIMEAAIRBORNESYSTEM_RGBIMAGE_H
#include <iostream>
#include <string>
#include <QObject>
#include <QImage>
#include <opencv2/opencv.hpp>//包含了所有东西,编译很慢
using namespace cv;
class rgbImage :public QObject
{
Q_OBJECT
public:
rgbImage(QWidget* pParent = NULL);
~rgbImage();
void SetRgbImageWidthAndHeight(int BandCount, int Sample, int FrameNumber);
void FillRgbImage(unsigned short *datacube);
void FillFocusGrayImage(unsigned short *datacube);
void FillFocusGrayQImage(unsigned short * datacube);
void FillOnerowofRgbImage(cv::Mat * matRgbImage, int rowNumber, unsigned short *datacube);
QImage *m_QRgbImage;
cv::Mat *m_matRgbImage;
QImage *m_qimageFocusGrayImage;
cv::Mat *m_matFocusGrayImage;//用于调焦时,显示一帧的灰度图
//cv::Mat m_matFocusGrayImage;//用于调焦时,显示一帧的灰度图
CvVideoWriter *m_frame_writer;
VideoWriter m_VideoWriter;
// VideoWriter m_video("appsrc ! autovideoconvert ! filesink location=/media/nvme/delete/live.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480));
// VideoWriter video("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480));//
//控制该填充rgb图像第几帧数据
//以下两种情况需要重置为01调用函数SetRgbImageWidthAndHeight2每次开始填充数据前
int m_iFrameCounter;
int m_iFramerate;//
protected:
private:
int m_iSampleNumber;//
int m_iBandNumber;//
int m_iFrameNumber;//
public slots:
signals :
void sendstr(QString str);
void sendstr1(QString str);
void refreslabelimg(QImage* img1);
};
#endif //XIMEAAIRBORNESYSTEM_RGBIMAGE_H

View File

@ -69,8 +69,7 @@ namespace sbgtc
void sbgSolutionModeSignal(int); void sbgSolutionModeSignal(int);
void sbgAccuracySignal(int); void sbgAccuracySignal(int, int);
}; };
} }

View File

@ -63,9 +63,12 @@ public slots:
void sendSerialPortStatus(int serialPortStatus); void sendSerialPortStatus(int serialPortStatus);
void sendSbgSolutionModeState(int SolutionMode); void sendSbgSolutionModeState(int SolutionMode);
void sendSbgAccuracyState(int Accuracy); void sendSbgAccuracyState(int Accuracy,int SatelliteCounter);
void sendXimeaImageStatus(int ximeaImageStatus); void sendXimeaImageStatus(int ximeaImageStatus);
void sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime);
void sendXimeaBinState(int spatialBin, int spectralBin);
void sendXimeaImageFrameRate(double frameRate);
void sendCopyFileStatus(int fileStatus); void sendCopyFileStatus(int fileStatus);
}; };
#endif // UDPSERVER_H #endif // UDPSERVER_H

View File

@ -2,15 +2,22 @@
#define UTILITY_TC_H #define UTILITY_TC_H
#include <iostream> #include <iostream>
#include <ctime>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
QString getFileNameBaseOnTime(); QString getFileNameBaseOnTime();
QString formatTimeStr(char * format);
//https://blog.csdn.net/MoreWindows/article/details/6657829 //https://blog.csdn.net/MoreWindows/article/details/6657829
void bubbleSort(unsigned short * a, int n); void bubbleSort(unsigned short * a, int n);
void swap(unsigned short * a, unsigned short * b); void swap(unsigned short * a, unsigned short * b);
bool createDir(QString fullPath);
QList<QString> getFileInfo(QString file);
#endif // UTILITY_TC_H #endif // UTILITY_TC_H

View File

@ -25,10 +25,13 @@
#include <fstream> #include <fstream>
#include <unistd.h> #include <unistd.h>
#include <exception> #include <exception>
#include <fcntl.h>
#include <sys/mman.h>
#include <QObject> #include <QObject>
#include <QDateTime> #include <QDateTime>
#include <qthread.h> #include <qthread.h>
#include <QDir>
#include "configfile.h" #include "configfile.h"
@ -36,6 +39,13 @@
#include "math.h" #include "math.h"
#include "utility_tc.h" #include "utility_tc.h"
#include "MemoryPool.h"
#include <queue>
#include <QMutex>
#include "rgbImage.h"
//#ifdef WIN32 //#ifdef WIN32
//#include <xiApi.h> // Windows //#include <xiApi.h> // Windows
@ -43,6 +53,23 @@
//#include <m3api/xiApi.h> // Linux, OSX //#include <m3api/xiApi.h> // Linux, OSX
//#endif //#endif
//struct DataBuffer
//{
// unsigned short data[409200/2];
//};
class DataBuffer
{
public:
DataBuffer();
~DataBuffer();
unsigned short data[41040000];//1368*300*100=41040000为了兼容所有设置spectral bin和spatial bin
private:
};
class RecordXimeaTemperature : public QObject class RecordXimeaTemperature : public QObject
{ {
Q_OBJECT Q_OBJECT
@ -63,16 +90,48 @@ signals:
}; };
//queue<DataBuffer *> q;
//static QMutex r_qtx{ QMutex::Recursive };
static std::mutex r_qtx;
class WriteData2Disk : public QObject
{
Q_OBJECT
public:
WriteData2Disk();
void setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
private:
queue<DataBuffer *> * m_q;
queue<int> * m_qFrameCounter;
QString m_QbaseFileName;
int m_iFrameSizeInByte;
int m_iNumber_WriteDisk;
MemoryPool<DataBuffer> * m_pool;
bool isExitWriteData2Disk;
rgbImage * m_rgbImage;
public slots:
void write2Disk();
void exitWriteData2Disk();
signals:
};
class XimeaImager : public QObject class XimeaImager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
XimeaImager(); XimeaImager();
~XimeaImager();
void setFramerate(double framerate); void setFramerate(double framerate);
double getFramerate(); double getFramerate();
double setExposureTime(float exposureTime); double setExposureTime(float exposureTime);
int wrapSetExposureTime(float exposureTime_in_us);
double getExposureTime(); double getExposureTime();
double autoExposure(); double autoExposure();
void setGain(double gain); void setGain(double gain);
@ -86,6 +145,7 @@ public:
void stopRecord(); void stopRecord();
int getFrameCounter(); int getFrameCounter();
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel); int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
@ -95,46 +155,47 @@ private:
int m_iImagerState; int m_iImagerState;
int m_iImagerStateTemp; int m_iImagerStateTemp;
int m_iOffsetyOfSpectralBin1, m_iOffsetyOfSpectralBin2;
int m_iHeightOfSpectralBin1, m_iHeightOfSpectralBin2;
QThread * m_recordTempThread; QThread * m_recordTempThread;
RecordXimeaTemperature * m_ximeaTemperature; RecordXimeaTemperature * m_ximeaTemperature;
QThread * writeData2DiskThread;
WriteData2Disk * writeData2Disk;
queue<DataBuffer *> * q;
queue<int> * m_qFrameCounter;
MemoryPool<DataBuffer> * m_pool;
QString m_baseFileName; QString m_baseFileName;
QString m_ximeaTemperatureCSVPath; QString m_ximeaTemperatureCSVPath;
Iris::IrisXimeaImager m_imager; Iris::IrisXimeaImager m_imager;
unsigned short * m_buffer; unsigned short * m_buffer;
// MemoryPool<unsigned short> m_pool;
bool m_bRecordControl; bool m_bRecordControl;
int m_iFrameCounter; int m_iFrameCounter;
int m_iFrameSizeInByte; int m_iFrameSizeInByte;
rgbImage * m_rgbImage;
void writeHdr(); void writeHdr();
void processXiApiErrorCodes(int xiApiErrorCodes); void processXiApiErrorCodes(int xiApiErrorCodes);
inline double getSbgTime(double TimeDifferenceBetweensOSAndSbg) inline double getSbgTime(XI_IMG * image, double timeDifferenceBetweenSbgAndXimea)
{ {
struct timespec systemTime; double ximeaTime = (double)image->tsSec + (double)image->tsUSec/1000000;
clock_gettime(CLOCK_REALTIME,&systemTime); return ximeaTime + timeDifferenceBetweenSbgAndXimea;
tm systemTime_rili;
localtime_r(&systemTime.tv_sec, &systemTime_rili);
double secondSystem=(systemTime_rili.tm_mday-1)*24*60*60+systemTime_rili.tm_hour*60*60+systemTime_rili.tm_min*60+systemTime_rili.tm_sec;
double nanosecondSystem=secondSystem+static_cast<double>(systemTime.tv_nsec)/1000000000;
// printf("\n");
// printf("XimeaImager::getSbgTime------系统时间纳秒%d\n", systemTime.tv_nsec);
// printf("XimeaImager::getSbgTime------系统时间(未偏移)%f\n", nanosecondSystem);
// printf("XimeaImager::getSbgTime------系统时间(偏移)%f\n", nanosecondSystem-TimeDifferenceBetweensOSAndSbg);
return nanosecondSystem-TimeDifferenceBetweensOSAndSbg;
} }
Configfile m_configfile; Configfile m_configfile;
public slots: public slots:
void openImger(); void openImger();
void closeImger(); void closeImger();
double calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * m_image, double timeDifferenceBetweenSbgAndOS);
void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName); void startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName);
signals: signals:
@ -142,5 +203,10 @@ signals:
void ximeaImageStatus(int); void ximeaImageStatus(int);
void recordXimeaTemperatureSignal(QString); void recordXimeaTemperatureSignal(QString);
void startWriteDiskSignal();
void autoExposeMaxValueOfOneFrame(int, double);
void frameRateSignal(double);
void binSignal(int, int);
}; };
#endif // XIMEAIMAGER_H #endif // XIMEAIMAGER_H

View File

@ -43,17 +43,32 @@ bool Configfile::parseConfigfile()
} }
} }
bool Configfile::getBin(int &bin) bool Configfile::getSpectralBin(int &spectralBin)
{ {
try try
{ {
bin = cfg.lookup("bin"); spectralBin = cfg.lookup("spectralBin");
return true; return true;
} }
catch(const SettingNotFoundException &nfex) catch(const SettingNotFoundException &nfex)
{ {
cerr << "No 'bin' setting in configuration file." << endl; cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool Configfile::getspatialBin(int &spatialBin)
{
try
{
spatialBin = cfg.lookup("spatialBin");
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spatialBin' setting in configuration file." << endl;
return false; return false;
} }
} }
@ -62,22 +77,41 @@ bool Configfile::getEffectiveWindow(int &width, int &offsetx, int &height, int &
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &effective_window = root["effective_window"]; int spatialBin;
int count = effective_window.getLength(); int spectralBin;
getspatialBin(spatialBin);
getSpectralBin(spectralBin);
int bin; string spatialBinString;
getBin(bin); if(spatialBin == 1)
{
spatialBinString = "bin1";
}
else
{
spatialBinString = "bin2";
}
const Setting &spatialArgument = root["effective_window"][spatialBinString]["spatial"];
if(!(spatialArgument.lookupValue("width", width)
&& spatialArgument.lookupValue("offsetx", offsetx)))
{
return false;
}
const Setting &window = effective_window[bin-1]; string spectralBinString;
string name = window.getName(); if(spectralBin == 1)
{
if(!(window.lookupValue("width", width) spectralBinString = "bin1";
&& window.lookupValue("offsetx", offsetx) }
&& window.lookupValue("height", height) else
&& window.lookupValue("offsety", offsety))) {
spectralBinString = "bin2";
}
const Setting &spectralArgument = root["effective_window"][spectralBinString]["spectral"];
if(!(spectralArgument.lookupValue("height", height)
&& spectralArgument.lookupValue("offsety", offsety)))
{ {
return false; return false;
} }
@ -95,16 +129,25 @@ bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx)
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &effective_window = root["effective_window_roi"]; const Setting &effective_window = root["effective_window_roi"];
int count = effective_window.getLength(); int count = effective_window.getLength();
int bin; int spatialBin;
getBin(bin); getspatialBin(spatialBin);
const Setting &window = effective_window[bin-1]; string spatialBinString;
if(spatialBin == 1)
{
spatialBinString = "spatialBin1";
}
else
{
spatialBinString = "spatialBin2";
}
const Setting &window = effective_window[spatialBinString];
string name = window.getName(); string name = window.getName();
if(!(window.lookupValue("width", width) if(!(window.lookupValue("width", width)
@ -123,20 +166,51 @@ bool Configfile::getEffectiveWindowRoi(int &width, int &offsetx)
return true; return true;
} }
bool Configfile::getWindowOffsety_HeightOfSpectral(int &offsety, int &height, string spectralBinString)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &spectralArgument = root["effective_window"][spectralBinString]["spectral"];
if(!(spectralArgument.lookupValue("height", height)
&& spectralArgument.lookupValue("offsety", offsety)))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getGainOffset(float &gain, float &offset) bool Configfile::getGainOffset(float &gain, float &offset)
{ {
const Setting& root = cfg.getRoot(); const Setting& root = cfg.getRoot();
// Output a list of all books in the inventory.
try try
{ {
const Setting &gainOffset = root["gainOffset"]; const Setting &gainOffset = root["gainOffset"];
int count = gainOffset.getLength(); int count = gainOffset.getLength();
int bin; int spectralBin;
getBin(bin); getSpectralBin(spectralBin);
const Setting &gainOffsetSetting = gainOffset[bin-1]; string spectralBinString;
if(spectralBin == 1)
{
spectralBinString = "spectralBin1";
}
else
{
spectralBinString = "spectralBin2";
}
const Setting &gainOffsetSetting = gainOffset[spectralBinString];
string name = gainOffsetSetting.getName(); string name = gainOffsetSetting.getName();
if(!(gainOffsetSetting.lookupValue("gain", gain) if(!(gainOffsetSetting.lookupValue("gain", gain)
@ -154,69 +228,171 @@ bool Configfile::getGainOffset(float &gain, float &offset)
return true; return true;
} }
bool Configfile::getGainOffsetOfSpectralBin1(float &gain, float &offset)
{
const Setting& root = cfg.getRoot();
try
{
const Setting &gainOffset = root["gainOffset"];
int count = gainOffset.getLength();
string spectralBinString = "spectralBin1";
const Setting &gainOffsetSetting = gainOffset[spectralBinString];
string name = gainOffsetSetting.getName();
if(!(gainOffsetSetting.lookupValue("gain", gain)
&& gainOffsetSetting.lookupValue("offset", offset)))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
// Ignore.
return false;
}
return true;
}
bool Configfile::getSN(QString &SN)
{
try
{
std::string SN_tem = cfg.lookup("SN");
SN = QString::fromStdString(SN_tem);
return true;
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
}
bool Configfile::getBufferPolicy(int &bufferPolicy)
{
const Setting& root = cfg.getRoot();
const Setting &ximeadll = root["ximeadll"];
try
{
if(!(ximeadll.lookupValue("buffer_policy", bufferPolicy)
))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
return true;
}
bool Configfile::getAcqBufferSize(int &acqBufferSize)
{
const Setting& root = cfg.getRoot();
const Setting &ximeadll = root["ximeadll"];
try
{
if(!(ximeadll.lookupValue("acq_buffer_size", acqBufferSize)
))
{
return false;
}
}
catch(const SettingNotFoundException &nfex)
{
cerr << "No 'spectralBin' setting in configuration file." << endl;
return false;
}
return true;
}
bool Configfile::createConfigFile() bool Configfile::createConfigFile()
{ {
using namespace std; using namespace std;
using namespace libconfig; using namespace libconfig;
static const char *output_file = "ximea.cfg";
Config cfg; Config cfg;
Setting &root = cfg.getRoot(); Setting &root = cfg.getRoot();
// Add some settings to the configuration. // Add some settings to the configuration.
Setting &bin = root.add("bin", Setting::TypeInt) = 1;
Setting &SN = root.add("SN", Setting::TypeString) = "0098"; Setting &SN = root.add("SN", Setting::TypeString) = "0098";
Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 2;
Setting &SpectralBin = root.add("spectralBin", Setting::TypeInt) = 2;
Setting &effective_window = root.add("effective_window", Setting::TypeGroup); Setting &effective_window = root.add("effective_window", Setting::TypeGroup);
Setting &effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup); Setting &effective_window_Bin1 = effective_window.add("bin1", Setting::TypeGroup);
Setting &effective_window_Bin1_spatial = effective_window_Bin1.add("spatial", Setting::TypeGroup);
Setting &effective_window_Bin1_Spectral = effective_window_Bin1.add("spectral", Setting::TypeGroup);
Setting &effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup); Setting &effective_window_Bin2 = effective_window.add("bin2", Setting::TypeGroup);
Setting &effective_window_Bin2_spatial = effective_window_Bin2.add("spatial", Setting::TypeGroup);
Setting &effective_window_Bin2_Spectral = effective_window_Bin2.add("spectral", Setting::TypeGroup);
effective_window_Bin1.add("width", Setting::TypeInt) = 1392; effective_window_Bin1_spatial.add("width", Setting::TypeInt) = 1368;
effective_window_Bin1.add("offsetx", Setting::TypeInt) = 272; effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 288;
effective_window_Bin1.add("height", Setting::TypeInt) = 300; effective_window_Bin1_Spectral.add("height", Setting::TypeInt) = 300;
effective_window_Bin1.add("offsety", Setting::TypeInt) = 348; effective_window_Bin1_Spectral.add("offsety", Setting::TypeInt) = 348;
effective_window_Bin2.add("width", Setting::TypeInt) = 712; effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 688;
effective_window_Bin2.add("offsetx", Setting::TypeInt) = 128; effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 144;
effective_window_Bin2.add("height", Setting::TypeInt) = 151; effective_window_Bin2_Spectral.add("height", Setting::TypeInt) = 150;
effective_window_Bin2.add("offsety", Setting::TypeInt) = 174; effective_window_Bin2_Spectral.add("offsety", Setting::TypeInt) = 174;
Setting &effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup); Setting &effective_window_roi = root.add("effective_window_roi", Setting::TypeGroup);
Setting &effective_window_roi_Bin1 = effective_window_roi.add("bin1", Setting::TypeGroup); Setting &effective_window_roi_spatialBin1 = effective_window_roi.add("spatialBin1", Setting::TypeGroup);
Setting &effective_window_roi_Bin2 = effective_window_roi.add("bin2", Setting::TypeGroup); Setting &effective_window_roi_spatialBin2 = effective_window_roi.add("spatialBin2", Setting::TypeGroup);
effective_window_roi_Bin1.add("width", Setting::TypeInt) = 1364; effective_window_roi_spatialBin1.add("width", Setting::TypeInt) = 1364;
effective_window_roi_Bin1.add("offsetx", Setting::TypeInt) = 14; effective_window_roi_spatialBin1.add("offsetx", Setting::TypeInt) = 14;
// effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300; // effective_window_roi_Bin1.add("height", Setting::TypeInt) = 300;
// effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348; // effective_window_roi_Bin1.add("offsety", Setting::TypeInt) = 348;
effective_window_roi_Bin2.add("width", Setting::TypeInt) = 682; effective_window_roi_spatialBin2.add("width", Setting::TypeInt) = 682;
effective_window_roi_Bin2.add("offsetx", Setting::TypeInt) = 15; effective_window_roi_spatialBin2.add("offsetx", Setting::TypeInt) = 15;
// effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151; // effective_window_roi_Bin2.add("height", Setting::TypeInt) = 151;
// effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174; // effective_window_roi_Bin2.add("offsety", Setting::TypeInt) = 174;
Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup); Setting &gainOffset = root.add("gainOffset", Setting::TypeGroup);
Setting &gainOffsetBin1 = gainOffset.add("bin1", Setting::TypeGroup); Setting &gainOffsetSpectralBin1 = gainOffset.add("spectralBin1", Setting::TypeGroup);
Setting &gainOffsetBin2 = gainOffset.add("bin2", Setting::TypeGroup); Setting &gainOffsetSpectralBin2 = gainOffset.add("spectralBin2", Setting::TypeGroup);
gainOffsetBin1.add("gain", Setting::TypeFloat) = 2.00313433; gainOffsetSpectralBin1.add("gain", Setting::TypeFloat) = 2.00313433;
gainOffsetBin1.add("offset", Setting::TypeFloat) = -300.46283157590585; gainOffsetSpectralBin1.add("offset", Setting::TypeFloat) = -300.46283157590585;
gainOffsetBin2.add("gain", Setting::TypeFloat) = 4.00626868; gainOffsetSpectralBin2.add("gain", Setting::TypeFloat) = 4.00626868;
gainOffsetBin2.add("offset", Setting::TypeFloat) = -299.46126663407176; gainOffsetSpectralBin2.add("offset", Setting::TypeFloat) = -299.46126663407176;
Setting &ximeadll = root.add("ximeadll", Setting::TypeGroup);
ximeadll.add("buffer_policy", Setting::TypeInt) = 0;
ximeadll.add("acq_buffer_size", Setting::TypeInt) = 400;
// Write out the new configuration. // Write out the new configuration.
QString output_file = "/media/nvme/300TC/config/ximea.cfg";
try try
{ {
cfg.writeFile(output_file); QList<QString> fileInfo = getFileInfo(output_file);
cerr << "New configuration successfully written to: " << output_file << endl; bool ret = createDir(fileInfo[0]);
cfg.writeFile(output_file.toStdString().c_str());
cerr << "New configuration successfully written to: " << output_file.toStdString().c_str() << endl;
} }
catch(const FileIOException &fioex) catch(const FileIOException &fioex)
{ {
cerr << "I/O error while writing configuration file: " << output_file << endl; cerr << "I/O error while writing configuration file: " << output_file.toStdString().c_str() << endl;
return true; return true;
} }

View File

@ -3,6 +3,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::cout<<"ximeaAirborneSystem 版本:"<< "36." <<std::endl;
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
//UdpServer* x=new UdpServer(); //UdpServer* x=new UdpServer();

253
Source_Files/rgbImage.cpp Normal file
View File

@ -0,0 +1,253 @@
//
// Created by tangchao on 2022/12/24.
//
#include "../Header_Files/rgbImage.h"
rgbImage::rgbImage(QWidget* pParent)
{
m_QRgbImage = nullptr;
m_matRgbImage = nullptr;
m_matFocusGrayImage = nullptr;
m_qimageFocusGrayImage = nullptr;
}
rgbImage::~rgbImage()
{
}
void rgbImage::SetRgbImageWidthAndHeight(int BandCount, int Sample, int FrameNumber)
{
using namespace cv;
if (m_QRgbImage != nullptr)
{
delete m_QRgbImage;//有问题????????????????????????????????????????????????
}
//m_QRgbImage = new QImage(Sample, FrameNumber, QImage::Format_RGB888);
if (m_matRgbImage != nullptr)
{
delete m_matRgbImage;
}
m_matRgbImage = new Mat(FrameNumber, Sample, CV_8UC3, Scalar(0, 0, 0));
int codec = VideoWriter::fourcc('M', 'P', '4', '2'); // select desired codec (must be available at runtime)
double fps = 20.0; // framerate of the created video stream
std::string filename = "appsrc ! autovideoconvert ! filesink location=/media/nvme/delete/live.avi";//https://blog.csdn.net/ancientapesman/article/details/117324638
m_VideoWriter.open(filename, codec, fps, m_matRgbImage->size(), true);
// VideoWriter video("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480));
// m_frame_writer = cvCreateVideoWriter("/media/nvme/delete/live.avi", cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 20.0, Size(688, 688), false);
if (m_qimageFocusGrayImage == nullptr)
{
m_qimageFocusGrayImage = new QImage(Sample, BandCount, QImage::Format_RGB32);
}
if (m_matFocusGrayImage == nullptr)
{
m_matFocusGrayImage = new Mat(BandCount, Sample, CV_16U, Scalar(0));
//cv::Mat matAdjustPreview = Mat::zeros(BandCount, Sample, CV_16U);
}
//cv::Mat matAdjustPreview = Mat::zeros(BandCount, Sample, CV_16U);
//m_matFocusGrayImage = matAdjustPreview;
std::cout << "设置帧数:" << FrameNumber << std::endl;
m_iFrameCounter = 0;//每次都重置为0
m_iSampleNumber = Sample;
m_iBandNumber = BandCount;
m_iFrameNumber = FrameNumber;
//std::cout << "rgb影像内存地址为" << m_QRgbImage << std::endl;
}
void rgbImage::FillOnerowofRgbImage(cv::Mat * matRgbImage, int rowNumber, unsigned short *datacube)
{
unsigned short r, g, b;
for (int j = 0; j < m_iSampleNumber; j++)
{
//取值一帧影像中从左到右的rgb像元值
r = *(datacube + 121 * m_iSampleNumber + j)*255/4096;
g = *(datacube + 79 * m_iSampleNumber + j)*255/4096;
b = *(datacube + 40 * m_iSampleNumber + j)*255/4096;
//将像元值赋值到cv::Mat中操作像元值https://zhuanlan.zhihu.com/p/51842288
//int dataType = m_matRgbImage->type();//当数据类型为CV_16UC3时返回18
//std::cout << "m_matRgbImage数据类型为" << dataType << std::endl;
if (matRgbImage->type() == CV_16UC3)
{
//std::cout << "操作像素值!" << std::endl;
matRgbImage->at<cv::Vec3w>(rowNumber, j)[2] = r;
matRgbImage->at<cv::Vec3w>(rowNumber, j)[1] = g;
matRgbImage->at<cv::Vec3w>(rowNumber, j)[0] = b;
}
}
}
void rgbImage::FillRgbImage(unsigned short *datacube)
{
unsigned short *r_row, *g_row, *b_row;
if(m_iFrameCounter<m_iFrameNumber)
{
FillOnerowofRgbImage(m_matRgbImage, m_iFrameCounter, datacube);
// std::cout << "小于:" << m_iFrameNumber << std::endl;
}
else
{
// std::cout << "大于:" << m_iFrameNumber << std::endl;
//通过行赋值将前m_iFrameNumber-1行向上移动一行https://blog.csdn.net/u014686356/article/details/65937750
// m_matRgbImage->rowRange(1, m_matRgbImage->rows).copyTo(m_matRgbImage->rowRange(0, m_matRgbImage->rows-1));
for (int i = 1; i < m_matRgbImage->rows; ++i)
{
// std::cout << "大于:" << i << std::endl;
m_matRgbImage->col(i).copyTo(m_matRgbImage->col(i-1));
// std::cout << "--------------" << i << std::endl;
}
// std::cout << "1111111111111111111111111111"<< std::endl;
//通过FillOnerowofRgbImage为m_iFrameNumber行赋值
FillOnerowofRgbImage(m_matRgbImage, m_iFrameNumber-1, datacube);
// std::cout << "22222222222222222"<< std::endl;
// //循环给每行像素赋值
// r_row = datacube + 121 * m_iSampleNumber;
// g_row = datacube + 79 * m_iSampleNumber;
// b_row = datacube + 40 * m_iSampleNumber;
// for (int j = 0; j < m_iFrameNumber; j++)
// {
// p = m_matRgbImage.ptr<uchar>(j);
// for ( j = 0; j < nCols; ++j){
// p[j] = table[p[j]];
// }
//
// }
//保存rgb图片
if (m_iFrameCounter % m_iFramerate == 0 || m_iFrameCounter == m_iFrameNumber - 1)
{
////保存文件
//FileOperation * fileOperation = new FileOperation();
//string directory = fileOperation->getDirectoryOfExe();
//string rgbFilePathStrech = “/media/nvme/300TC/config/” + "\\tmp_image_strech.png";//没有拉伸图片
// std::string rgbFilePathNoStrech = "/media/nvme/300TC/config/" + std::to_string(m_iFrameCounter) + "ctmp_image_no_strech.png";
//m_QRgbImage->save(QString::fromStdString(rgbFilePathNoStrech), "PNG");
// cv::imwrite(rgbFilePathNoStrech, *m_matRgbImage);
//cv::imwrite(rgbFilePathStrech, CStretch(*m_matRgbImage, 0.01));
}
m_VideoWriter.write(*m_matRgbImage);
std::string rgbFilePathNoStrech = "/media/nvme/delete/" + std::to_string(m_iFrameCounter) + "ctmp_image_no_strech.png";
cv::imwrite(rgbFilePathNoStrech, *m_matRgbImage);
}
m_iFrameCounter++;
}
void rgbImage::FillFocusGrayImage(unsigned short * datacube)
{
int rowCount = m_matFocusGrayImage->rows;
int colCount = m_matFocusGrayImage->cols;
for (unsigned short i = 0; i < m_matFocusGrayImage->rows; i++)
{
for (unsigned short j = 0; j < m_matFocusGrayImage->cols; j++)
{
//m_matFocusGrayImage->at<ushort>(i, j) = *(datacube + m_matFocusGrayImage->cols*i + j);
m_matFocusGrayImage->at<ushort>(i, j) = datacube[m_matFocusGrayImage->cols*i + j];
}
}
//int rowCount = m_matFocusGrayImage.rows;
//int colCount = m_matFocusGrayImage.cols;
////memcpy(m_matFocusGrayImage.data, datacube, rowCount*colCount);
//for (unsigned short i = 0; i < m_matFocusGrayImage.rows; i++)
//{
// for (unsigned short j = 0; j < m_matFocusGrayImage.cols; j++)
// {
// m_matFocusGrayImage.at<ushort>(i, j) = *(datacube + m_matFocusGrayImage.cols*i + j);
// //m_matFocusGrayImage.at<ushort>(i, j) = datacube[colCount*i + j];
// }
//}
//将mat保存成文件
//cv::imwrite("D:/delete/2222222222/test.bmp", m_matFocusGrayImage);
}
void rgbImage::FillFocusGrayQImage(unsigned short * datacube)
{
float two_eight = pow(2.0, 8);
float two_sixteen = pow(2.0, 12);
int width = m_qimageFocusGrayImage->width();
int height = m_qimageFocusGrayImage->height();
for (unsigned short i = 0; i < height; i++)
{
for (unsigned short j = 0; j < width; j++)
{
//uint tmp = (two_eight* *(datacube + width * i + j)) / two_sixteen;
uint tmp = (two_eight* datacube[width*i + j]) / two_sixteen;
//uint tmp = datacube[width*i + j];
//m_qimageFocusGrayImage->setPixel(j, i, tmp);
m_qimageFocusGrayImage->setPixel(j, i, qRgb((unsigned char)tmp, (unsigned char)tmp, (unsigned char)tmp));
}
}
m_qimageFocusGrayImage->save("D:/delete/2222222222/test.bmp");
/*float two_eight = pow(2.0, 8);
float two_sixteen = pow(2.0, 16);
QImage *qi = new QImage(imwidth, imheight, QImage::Format_RGB32);
for (int i = 0; i < imheight; i++)
{
for (int j = 0; j < imwidth; j++)
{
floatData[i*imwidth + j] = (two_eight* floatData[i*imwidth + j]) / two_sixteen;
qi->setPixel(j, i, qRgb((unsigned char)floatData[i*imwidth + j], (unsigned char)floatData[i*imwidth + j], (unsigned char)floatData[i*imwidth + j]));
}
}*/
}

View File

@ -53,7 +53,7 @@ void sbgtc::SbgRecorder::openSerialPort()
} }
// QString portname = "sbg_serial_port"; // QString portname = "sbg_serial_port";
QString portname = "ttyS4"; QString portname = "ttyUSB0";
m_serial->setPortName(portname); m_serial->setPortName(portname);
m_serial->open(QIODevice::ReadWrite); m_serial->open(QIODevice::ReadWrite);
@ -622,19 +622,19 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
switch (mode) switch (mode)
{ {
case SBG_ECOM_SOL_MODE_UNINITIALIZED: case SBG_ECOM_SOL_MODE_UNINITIALIZED:
std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl; // std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl;
break; break;
case SBG_ECOM_SOL_MODE_VERTICAL_GYRO: case SBG_ECOM_SOL_MODE_VERTICAL_GYRO:
std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl; // std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl;
break; break;
case SBG_ECOM_SOL_MODE_AHRS: case SBG_ECOM_SOL_MODE_AHRS:
std::cout<<"此刻模式为: "<<"AHRS"<<std::endl; // std::cout<<"此刻模式为: "<<"AHRS"<<std::endl;
break; break;
case SBG_ECOM_SOL_MODE_NAV_VELOCITY: case SBG_ECOM_SOL_MODE_NAV_VELOCITY:
std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl; // std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl;
break; break;
case SBG_ECOM_SOL_MODE_NAV_POSITION: case SBG_ECOM_SOL_MODE_NAV_POSITION:
std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl; // std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl;
break; break;
default: default:
@ -671,13 +671,11 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
} }
else if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_GPS1_POS) else if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_GPS1_POS)
{ {
// std::cout<<"纬度精度为:"<<logData.gpsPosData.latitudeAccuracy<<std::endl;
float maximal=0; float maximal=0;
float latitudeAccuracy=logData.gpsPosData.latitudeAccuracy; float latitudeAccuracy=logData.gpsPosData.latitudeAccuracy;
float longitudeAccuracy=logData.gpsPosData.longitudeAccuracy; float longitudeAccuracy=logData.gpsPosData.longitudeAccuracy;
float altitudeAccuracy=logData.gpsPosData.altitudeAccuracy; float altitudeAccuracy=logData.gpsPosData.altitudeAccuracy;
int satelliteCounter=(int)logData.gpsPosData.numSvUsed;
if(latitudeAccuracy<longitudeAccuracy) if(latitudeAccuracy<longitudeAccuracy)
maximal = longitudeAccuracy; maximal = longitudeAccuracy;
@ -687,7 +685,10 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
if(maximal<altitudeAccuracy) if(maximal<altitudeAccuracy)
maximal = altitudeAccuracy; maximal = altitudeAccuracy;
emit sbgAccuracySignal(static_cast<int>(maximal)); // std::cout<<"纬度精度为:"<<maximal<<std::endl;
// std::cout<<"numSvUsed"<<satelliteCounter<<std::endl;
emit sbgAccuracySignal(static_cast<int>(maximal), satelliteCounter);
if(maximal<7) if(maximal<7)
{ {
@ -710,15 +711,10 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
char setGpsTimeCommand[256]; char setGpsTimeCommand[256];
sprintf(setGpsTimeCommand,"date --set=\"%d%02d%02d %02d:%02d:%02d\"",year,month,day,hour,minute,second);//02中的2代表2位数字0代表以0补全 sprintf(setGpsTimeCommand,"date --set=\"%d%02d%02d %02d:%02d:%02d\"",year,month,day,hour,minute,second);//02中的2代表2位数字0代表以0补全
system(setGpsTimeCommand);// // system(setGpsTimeCommand);
m_bIsSyncSystemTimeBaseGpstime=true; m_bIsSyncSystemTimeBaseGpstime=true;
} }
else if(receivedMsgClass==SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_EULER)
{
// std::cout<<"1111111111111"<<"UTC time:"<<(int)logData.utcData.year<<","<<(int)logData.utcData.month<<","<<(int)logData.utcData.day<<","<<(int)logData.utcData.hour<<","<<(int)logData.utcData.minute<<","<<(int)(int)logData.utcData.second<<std::endl;
// std::cout<<"receivedMsg:"<<(int)receivedMsg<<std::endl;
}
else if(receivedMsgClass!=SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_QUAT) else if(receivedMsgClass!=SBG_ECOM_CLASS_LOG_ECOM_0 && receivedMsg==SBG_ECOM_LOG_EKF_QUAT)
{ {
//std::cout<<"1111111111111------"<<"UTC time:"<<(int)logData.utcData.year<<","<<(int)logData.utcData.month<<","<<(int)logData.utcData.day<<","<<(int)logData.utcData.hour<<","<<(int)logData.utcData.minute<<","<<(int)(int)logData.utcData.second<<std::endl; //std::cout<<"1111111111111------"<<"UTC time:"<<(int)logData.utcData.year<<","<<(int)logData.utcData.month<<","<<(int)logData.utcData.day<<","<<(int)logData.utcData.hour<<","<<(int)logData.utcData.minute<<","<<(int)(int)logData.utcData.second<<std::endl;
@ -793,7 +789,7 @@ void sbgtc::SbgRecorder::startRecordSbg()
m_baseFileName=getFileNameBaseOnTime(); m_baseFileName=getFileNameBaseOnTime();
QString sbgFileName=m_baseFileName+".sbg"; QString sbgFileName=m_baseFileName+".bin";
FILE * fileHandle=fopen(sbgFileName.toStdString().c_str(),"w+b"); FILE * fileHandle=fopen(sbgFileName.toStdString().c_str(),"w+b");
@ -802,7 +798,7 @@ void sbgtc::SbgRecorder::startRecordSbg()
while (m_bRecordControl) while (m_bRecordControl)
{ {
//std::cout<<"SbgRecorder::startRecordSbg--------------:"<<std::endl; //std::cout<<"SbgRecorder::startRecordSbg--------------:"<<std::endl;
if(m_serial->waitForReadyRead()) if(m_serial->waitForReadyRead(30000))
{ {
//requestData.resize(m_serial->size()); //requestData.resize(m_serial->size());
requestData = m_serial->readAll(); requestData = m_serial->readAll();

View File

@ -8,16 +8,16 @@ UdpServer::UdpServer()
m_udpSocket->bind(45454, QUdpSocket::ShareAddress); m_udpSocket->bind(45454, QUdpSocket::ShareAddress);
connect(m_udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams())); connect(m_udpSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));
m_RecordThread=new QThread();
m_imager=new XimeaImager();
m_imager->moveToThread(m_RecordThread);
m_RecordThread->start(QThread::HighestPriority);
m_RecordSbgThread=new QThread(); m_RecordSbgThread=new QThread();
m_sbgRecorder=new sbgtc::SbgRecorder(); m_sbgRecorder=new sbgtc::SbgRecorder();
m_sbgRecorder->moveToThread(m_RecordSbgThread); m_sbgRecorder->moveToThread(m_RecordSbgThread);
m_RecordSbgThread->start(); m_RecordSbgThread->start();
m_RecordThread=new QThread();
m_imager=new XimeaImager();
m_imager->moveToThread(m_RecordThread);
m_RecordThread->start();
m_CopyFileThread=new QThread(); m_CopyFileThread=new QThread();
m_copyFile=new FileOperation(); m_copyFile=new FileOperation();
m_copyFile->moveToThread(m_CopyFileThread); m_copyFile->moveToThread(m_CopyFileThread);
@ -47,9 +47,12 @@ UdpServer::UdpServer()
connect(m_sbgRecorder, SIGNAL(serialPortStatus(int)),this, SLOT(sendSerialPortStatus(int))); connect(m_sbgRecorder, SIGNAL(serialPortStatus(int)),this, SLOT(sendSerialPortStatus(int)));
connect(m_sbgRecorder, SIGNAL(sbgSolutionModeSignal(int)),this, SLOT(sendSbgSolutionModeState(int))); connect(m_sbgRecorder, SIGNAL(sbgSolutionModeSignal(int)),this, SLOT(sendSbgSolutionModeState(int)));
connect(m_sbgRecorder, SIGNAL(sbgAccuracySignal(int)),this, SLOT(sendSbgAccuracyState(int))); connect(m_sbgRecorder, SIGNAL(sbgAccuracySignal(int,int)),this, SLOT(sendSbgAccuracyState(int,int)));
connect(m_imager, SIGNAL(ximeaImageStatus(int)),this, SLOT(sendXimeaImageStatus(int))); connect(m_imager, SIGNAL(ximeaImageStatus(int)),this, SLOT(sendXimeaImageStatus(int)));
connect(m_imager, SIGNAL(autoExposeMaxValueOfOneFrame(int, double)),this, SLOT(sendXimeaAutoExposeMaxValueOfOneFrame(int, double)));
connect(m_imager, SIGNAL(binSignal(int, int)),this, SLOT(sendXimeaBinState(int, int)));
connect(m_imager, SIGNAL(frameRateSignal(double)),this, SLOT(sendXimeaImageFrameRate(double)));
connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int))); connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int)));
@ -57,10 +60,10 @@ UdpServer::UdpServer()
//当软件不正常关闭并且重启后通知其他psdk程序 //当软件不正常关闭并且重启后通知其他psdk程序
m_clientIpAddress=QHostAddress(QHostAddress::LocalHost); m_clientIpAddress=QHostAddress(QHostAddress::LocalHost);
sendSerialPortStatus(0); sendSerialPortStatus(0);
sendXimeaImageStatus(0); sendXimeaImageStatus(100);
sendCopyFileStatus(0); sendCopyFileStatus(0);
system("sudo gpio write 10 0");
std::cout<<"UdpServer::UdpServer--------:System ready!"<<std::endl; std::cout<<"UdpServer::UdpServer--------:System ready!"<<std::endl;
@ -88,6 +91,10 @@ void UdpServer::processPendingDatagrams()
case 1://启动系统: 打开sbg串口并采集数据打开光谱仪 case 1://启动系统: 打开sbg串口并采集数据打开光谱仪
{ {
std::cout<<"1代表启动系统!"<<std::endl; std::cout<<"1代表启动系统!"<<std::endl;
system("sudo gpio write 10 1");
sleep(4);//睡眠4秒等待电脑打开usb电源以便给相机供电
emit systemStart(); emit systemStart();
break; break;
@ -110,31 +117,27 @@ void UdpServer::processPendingDatagrams()
emit systemStop(); emit systemStop();
sleep(4);//睡眠4秒等待
system("sudo gpio write 10 0");
//QCoreApplication::quit(); //QCoreApplication::quit();
break; break;
} }
case 3://系统开始采集高光谱影像 case 3://系统开始采集高光谱影像
{ {
//emit startRecordHyperspectralSignal();//真实的影像开始采集通过惯导中的信号(sbgReady)触发 if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
{
std::cout<<"3代表系统开始采集高光谱影像!"<<std::endl;
m_sbgRecorder->startRecordHyperspectral(); m_sbgRecorder->startRecordHyperspectral();
}
// if(m_sbgRecorder->getSbgState()==2)//开始采集前还需要判断相机的状态??????????????????????????????????????????
// {
// }
// else if(m_sbgRecorder->getSbgState()==3)
// {
// std::cout<<"系统已经开始采集!"<<std::endl;
// }
break; break;
} }
case 4://系统停止采集高光谱影像 case 4://系统停止采集高光谱影像
{ {
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=104) if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=104)
{ {
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
m_imager->stopRecord(); m_imager->stopRecord();
} }
@ -162,17 +165,11 @@ void UdpServer::processPendingDatagrams()
} }
case 7: case 7:
{ {
if(datagramList[1].toInt()==1) if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
{ {
std::cout<<"拷贝数据!"<<std::endl; float time = datagramList[1].toFloat();//ms
m_imager->wrapSetExposureTime(time*1000);
emit startCopyFileSignal(); std::cout<<"7手动设置曝光时间为" << time <<std::endl;
}
else if(datagramList[1].toInt()==0)
{
std::cout<<"删除数据!"<<std::endl;
emit startDeleteFileSignal();
} }
break; break;
@ -253,9 +250,9 @@ void UdpServer::sender(int status)
void UdpServer::sendSerialPortStatus(int serialPortStatus) void UdpServer::sendSerialPortStatus(int serialPortStatus)
{ {
std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< serialPortStatus <<std::endl; // std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< serialPortStatus <<std::endl;
std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< m_clientIpAddress.AnyIPv4 <<std::endl; // std::cout<<"UdpServer::sendSerialPortStatus---------------------:"<< m_clientIpAddress.AnyIPv4 <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
@ -267,7 +264,7 @@ void UdpServer::sendSerialPortStatus(int serialPortStatus)
void UdpServer::sendSbgSolutionModeState(int SolutionMode) void UdpServer::sendSbgSolutionModeState(int SolutionMode)
{ {
std::cout<<"UdpServer::sendSbgSolutionModeState---------------------:"<< SolutionMode <<std::endl; // std::cout<<"UdpServer::sendSbgSolutionModeState---------------------:"<< SolutionMode <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
@ -277,13 +274,13 @@ void UdpServer::sendSbgSolutionModeState(int SolutionMode)
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455); m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
} }
void UdpServer::sendSbgAccuracyState(int Accuracy) void UdpServer::sendSbgAccuracyState(int Accuracy,int SatelliteCounter)
{ {
// std::cout<<"UdpServer::sendSbgAccuracyState---------------------:"<< Accuracy <<std::endl; // std::cout<<"UdpServer::sendSbgAccuracyState---------------------:"<< Accuracy <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
QString status = "Accuracy," + QString::number(Accuracy); QString status = "Accuracy," + QString::number(Accuracy) + "," + QString::number(SatelliteCounter);
datagram2send.operator =(status.toStdString().c_str()); datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455); m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
@ -291,7 +288,7 @@ void UdpServer::sendSbgAccuracyState(int Accuracy)
void UdpServer::sendXimeaImageStatus(int ximeaImageStatus) void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
{ {
std::cout<<"UdpServer::sendXimeaImageStatus---------------------:"<< ximeaImageStatus <<std::endl; // std::cout<<"UdpServer::sendXimeaImageStatus---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;
@ -301,9 +298,45 @@ void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455); m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
} }
void UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame(int autoExposeMaxValueOfOneFrame, double exposeTime)
{
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send;
QString status = "XimeaAutoExpose," + QString::number(autoExposeMaxValueOfOneFrame) + "," + QString::number(exposeTime, 'f', 2);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
}
void UdpServer::sendXimeaBinState(int spatialBin, int spectralBin)
{
// std::cout<<"UdpServer::sendXimeaAutoExposeMaxValueOfOneFrame---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send;
QString status = "bin," + QString::number(spatialBin) + "," + QString::number(spectralBin);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
}
void UdpServer::sendXimeaImageFrameRate(double frameRate)
{
// std::cout<<"UdpServer::sendXimeaImageFrameRate---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send;
QString status = "XimeaFrameRate," + QString::number(frameRate, 'f', 2);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
}
void UdpServer::sendCopyFileStatus(int fileStatus) void UdpServer::sendCopyFileStatus(int fileStatus)
{ {
std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl; // std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl;
QByteArray datagram2send; QByteArray datagram2send;

View File

@ -1,6 +1,25 @@
#include "Header_Files/utility_tc.h" #include "Header_Files/utility_tc.h"
#include <QDir> #include <QDir>
QString formatTimeStr(char * format)
{
//获取系统时间
time_t timer;//time_t就是long int 类型
struct tm *tblock;
timer = time(NULL);//返回秒数(精度为秒)从1970-1-1,00:00:00 可以当成整型输出或用于其它函数
tblock = localtime(&timer);
//printf("Local time is: %s\n", asctime(tblock));
//格式化时间为需要的格式
char timeStr_tmp[256] = { 0 };
strftime(timeStr_tmp, sizeof(timeStr_tmp), format, tblock);//
QString timeStr2(timeStr_tmp);
// qDebug() << "time is:" << timeStr2;
return timeStr2;
}
QString getFileNameBaseOnTime() QString getFileNameBaseOnTime()
{ {
using namespace std; using namespace std;
@ -69,3 +88,36 @@ void swap(unsigned short * a, unsigned short * b)
*a=*b; *a=*b;
*b=tmp; *b=tmp;
} }
bool createDir(QString fullPath)
{
QDir dir(fullPath);
if (dir.exists()) {
return true;
} else {
bool ok = dir.mkpath(fullPath);//创建多级目录
return ok;
}
}
QList<QString> getFileInfo(QString file)
{
QFileInfo fileInfo = QFileInfo(file);
QString fileName, fileSuffix, filePath;
filePath = fileInfo.absolutePath();//绝对路径
fileName = fileInfo.fileName();//文件名
fileSuffix = fileInfo.suffix();//文件后缀
// qDebug() << fileName <<endl
// << fileSuffix<< endl
// << filePath<< endl;
QList<QString> result;
result.append(filePath);
result.append(fileName);
result.append(fileSuffix);
return result;
}

View File

@ -7,12 +7,27 @@ XimeaImager::XimeaImager()
m_iFrameCounter=0; m_iFrameCounter=0;
m_iImagerState=100; m_iImagerState=100;
//connect(this, SIGNAL(recordFinished()),this, SLOT()); QString ximeaCfgFile = "/media/nvme/300TC/config/ximea.cfg";
m_configfile.setConfigfilePath(ximeaCfgFile.toStdString());
m_configfile.setConfigfilePath("ximea.cfg");
if(!m_configfile.isConfigfileExist()) if(!m_configfile.isConfigfileExist())
m_configfile.createConfigFile(); m_configfile.createConfigFile();
m_configfile.parseConfigfile(); m_configfile.parseConfigfile();
m_configfile.getWindowOffsety_HeightOfSpectral(m_iOffsetyOfSpectralBin1, m_iHeightOfSpectralBin1, "bin1");
m_configfile.getWindowOffsety_HeightOfSpectral(m_iOffsetyOfSpectralBin2, m_iHeightOfSpectralBin2, "bin2");
//检查 ximea.cfg 是否满足要求
if(m_iOffsetyOfSpectralBin2 != m_iOffsetyOfSpectralBin1 / 2)
{
std::cout<<"ximea.cfg 错误m_iOffsetyOfSpectralBin2 != m_iOffsetyOfSpectralBin1 / 2!"<<std::endl;
}
if(m_iOffsetyOfSpectralBin2 % 2 != 0)
{
std::cout<<"ximea.cfg 错误m_iOffsetyOfSpectralBin2 不是 2 的倍数ximea相机不接受!"<<std::endl;
}
if(m_iHeightOfSpectralBin1 < m_iHeightOfSpectralBin2 * 2)
{
std::cout<<"ximea.cfg 错误bin1 波段数小于 bin2 波段数的 2 倍!"<<std::endl;
}
m_recordTempThread=new QThread(); m_recordTempThread=new QThread();
m_ximeaTemperature = new RecordXimeaTemperature(&m_imager); m_ximeaTemperature = new RecordXimeaTemperature(&m_imager);
@ -20,6 +35,23 @@ XimeaImager::XimeaImager()
m_recordTempThread->start(); m_recordTempThread->start();
connect(this, SIGNAL(recordXimeaTemperatureSignal(QString)),m_ximeaTemperature, SLOT(recordTemperature(QString))); connect(this, SIGNAL(recordXimeaTemperatureSignal(QString)),m_ximeaTemperature, SLOT(recordTemperature(QString)));
writeData2DiskThread = new QThread();
writeData2Disk = new WriteData2Disk();
writeData2Disk->moveToThread(writeData2DiskThread);
writeData2DiskThread->start(QThread::HighestPriority);
connect(this, SIGNAL(startWriteDiskSignal()), writeData2Disk, SLOT(write2Disk()));
m_pool = new MemoryPool<DataBuffer>;
q = new queue<DataBuffer *>;
m_qFrameCounter = new queue<int>;
m_rgbImage = new rgbImage();
}
XimeaImager::~XimeaImager()
{
} }
void XimeaImager::openImger() void XimeaImager::openImger()
@ -36,18 +68,24 @@ void XimeaImager::openImger()
//std::cout<<"XimeaImager::openImger111111111111111111111:正在打开相机!"<<std::endl; //std::cout<<"XimeaImager::openImger111111111111111111111:正在打开相机!"<<std::endl;
m_imager.connect(); m_imager.connect();
bool ret; bool ret, ret1, ret2;
int bin=0; int spatialBin;
ret = m_configfile.getBin(bin); int spectralBin;
if (ret) ret1 = m_configfile.getspatialBin(spatialBin);
ret2 = m_configfile.getSpectralBin(spectralBin);
if (ret1 & ret2)
{ {
bool haha = m_imager.setSpectralBin(bin); bool haha = m_imager.setSpectralBin(spectralBin);
bool haha2 = m_imager.setSpatialBin(bin); bool haha2 = m_imager.setSpatialBin(spatialBin);
emit binSignal(spatialBin, spectralBin);
std::cout<<"spectralBin"<< spectralBin <<std::endl;
std::cout<<"spatialBin"<< spatialBin <<std::endl;
} }
float gain, offset;//用于生成头文件中的波长信息 float gain, offset;//用于生成头文件中的波长信息
ret = m_configfile.getGainOffset(gain, offset); ret = m_configfile.getGainOffsetOfSpectralBin1(gain, offset);
if (ret) if (ret)
{ {
m_imager.setGainOffset(gain, offset); m_imager.setGainOffset(gain, offset);
@ -58,13 +96,29 @@ void XimeaImager::openImger()
if (ret) if (ret)
{ {
m_imager.setEffectiveWindow(offsetx, width, offsety, height); m_imager.setEffectiveWindow(offsetx, width, offsety, height);
m_rgbImage->SetRgbImageWidthAndHeight(height, width, 20);
std::cout<<"height"<< height <<std::endl;
std::cout<<"width"<< width <<std::endl;
std::cout<<"每帧字节数:"<< width * height * 2 <<std::endl;
} }
int width_roi = 0, offsetx_roi = 0; // int width_roi = 0, offsetx_roi = 0;
ret = m_configfile.getEffectiveWindowRoi(width_roi, offsetx_roi); // ret = m_configfile.getEffectiveWindowRoi(width_roi, offsetx_roi);
if (ret) // if (ret)
// {
// m_imager.setEffectiveWindowRoi(offsetx_roi, width_roi);
// }
int bufferPolicy, acqBufferSize;
ret1 = m_configfile.getBufferPolicy(bufferPolicy);
if (ret1)
{ {
m_imager.setEffectiveWindowRoi(offsetx_roi, width_roi); m_imager.setBufferPolicy(bufferPolicy);
}
ret1 = m_configfile.getAcqBufferSize(acqBufferSize);
if (ret1)
{
m_imager.setAcqBufferSize(acqBufferSize);
} }
setFramerate(100); setFramerate(100);
@ -74,13 +128,17 @@ void XimeaImager::openImger()
int frameSizeAuto = m_imager.getBufferSizeOfOneFrame(); int frameSizeAuto = m_imager.getBufferSizeOfOneFrame();
m_iFrameSizeInByte = frameSizeAuto; m_iFrameSizeInByte = frameSizeAuto;
std::cout<<"每一帧的字节数:-------------------------------"<< m_iFrameSizeInByte <<std::endl;
m_buffer = new unsigned short[m_iFrameSizeInByte]; m_buffer = new unsigned short[m_iFrameSizeInByte];
m_iImagerState = 101; m_iImagerState = 101;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
m_ximeaTemperatureCSVPath = "/home/rock/programRunLog/ximeaTemperature.csv"; QDateTime curDateTime = QDateTime::currentDateTime();
QString currentTime = curDateTime.toString("yyyy_MM_dd_hh_mm_ss");
m_ximeaTemperatureCSVPath = QDir::cleanPath(QString::fromStdString("/home/programRunLog/hyperspectralLog") + QDir::separator() + "ximeaTemperature_" + currentTime + ".csv");
// m_ximeaTemperatureCSVPath = "/home/ximeaTemperature.csv";
emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath); emit recordXimeaTemperatureSignal(m_ximeaTemperatureCSVPath);
} }
catch(int xiApiErrorCodes) catch(int xiApiErrorCodes)
@ -128,12 +186,14 @@ void XimeaImager::setFramerate(double framerate)
{ {
m_imager.set_framerate(framerate); m_imager.set_framerate(framerate);
int maxExposureTimeInUs=1/framerate*1000000*0.8; int maxExposureTimeInUs=1/framerate*1000000*0.01;
setExposureTime(maxExposureTimeInUs); setExposureTime(maxExposureTimeInUs);
// setExposureTime(1000); // setExposureTime(1000);
m_iImagerState=102; m_iImagerState=102;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
emit frameRateSignal(framerate);
} }
catch(int xiApiErrorCodes) catch(int xiApiErrorCodes)
{ {
@ -190,6 +250,24 @@ double XimeaImager::setExposureTime(float exposureTime_in_us)
} }
} }
int XimeaImager::wrapSetExposureTime(float exposureTime_in_us)
{
double exposureTime = setExposureTime(exposureTime_in_us);
m_imager.start();
m_imager.get_frame(m_buffer);
m_imager.stop();
int maxValueOfOneFrame = getMaxValueOfOneFrame((short unsigned int*)m_imager.m_image.bp,m_imager.get_band_count()*m_imager.get_sample_count());
m_iImagerState=103;
emit ximeaImageStatus(m_iImagerState);
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime/1000);
return maxValueOfOneFrame;
}
double XimeaImager::autoExposure() double XimeaImager::autoExposure()
{ {
double exposureTime; double exposureTime;
@ -200,17 +278,20 @@ double XimeaImager::autoExposure()
float suitableMaxValue=4095 * 0.8; float suitableMaxValue=4095 * 0.8;
double framerate = m_imager.get_framerate(); double framerate = m_imager.get_framerate();
double maxExposureTime = 1/framerate*1000000; double maxExposureTime = 1/framerate*1000000*0.95;//0.95目的:避免曝光时间超过最大,而造成帧率降低
exposureTime=setExposureTime(maxExposureTime); exposureTime=setExposureTime(maxExposureTime);
bool bIsAutoExposureOk=false; bool bIsAutoExposureOk=false;
while(!bIsAutoExposureOk) while(!bIsAutoExposureOk)
{ {
std::cout<<"自动曝光本次时间为:"<< exposureTime <<std::endl;
m_imager.start(); m_imager.start();
m_imager.get_frame(m_buffer); m_imager.get_frame(m_buffer);
m_imager.stop(); m_imager.stop();
maxValueOfOneFrame=getMaxValueOfOneFrame(m_buffer,m_imager.get_band_count()*m_imager.get_sample_count()); maxValueOfOneFrame=getMaxValueOfOneFrame((short unsigned int*)m_imager.m_image.bp,m_imager.get_band_count()*m_imager.get_sample_count());
printf("本帧最大值为: %d.\n",maxValueOfOneFrame);
if(maxValueOfOneFrame <= suitableMaxValue) if(maxValueOfOneFrame <= suitableMaxValue)
{ {
@ -245,6 +326,7 @@ double XimeaImager::autoExposure()
m_iImagerState=103; m_iImagerState=103;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime/1000);
std::cout<<"自动曝光完成!"<<std::endl; std::cout<<"自动曝光完成!"<<std::endl;
return exposureTime; return exposureTime;
@ -402,7 +484,6 @@ int XimeaImager::getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel)
int a=0; int a=0;
} }
} }
printf("本帧最大值为: %d.\n",maxValue);
return maxValue; return maxValue;
} }
@ -412,6 +493,34 @@ int XimeaImager::getImagerState() const
return m_iImagerState; return m_iImagerState;
} }
double XimeaImager::calculateTimeDifferenceBetweenSbgAndximea(XI_IMG * image, double timeDifferenceBetweenSbgAndOS)
{
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--timeDifferenceBetweenSbgAndOS: %f s\n", timeDifferenceBetweenSbgAndOS);
double ximeaTime=image->tsSec + image->tsUSec/1000000;
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--ximeaTime: %f s\n", ximeaTime);
//获取系统时间(纳秒)
struct timespec systemTime;
clock_gettime(CLOCK_REALTIME,&systemTime);
tm systemTime_rili;
localtime_r(&systemTime.tv_sec, &systemTime_rili);
double secondSystem=(systemTime_rili.tm_mday-1)*24*60*60+systemTime_rili.tm_hour*60*60+systemTime_rili.tm_min*60+systemTime_rili.tm_sec;
double timeOS=secondSystem+static_cast<double>(systemTime.tv_nsec)/1000000000;
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--osTime: %f s\n", timeOS);
//计算系统时间和gps时间之间的差距
double timeDifferenceBetweenSbgAndximea = timeOS - timeDifferenceBetweenSbgAndOS - ximeaTime;
printf("XimeaImager::calculateTimeDifferenceBetweenSystemAndximea--timeDifferenceBetweenSbgAndximea: %f s\n", timeDifferenceBetweenSbgAndximea);
return timeDifferenceBetweenSbgAndximea;
}
void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName) void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString baseFileName)
{ {
m_ximeaTemperature->stopRecordTemperature();//开始采集影像前,停止获取相机的温度,以免降低帧率; m_ximeaTemperature->stopRecordTemperature();//开始采集影像前,停止获取相机的温度,以免降低帧率;
@ -429,87 +538,122 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
m_iImagerState=104; m_iImagerState=104;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
printf("开始采集!\n"); char * timeFormat="%Y%m%d_%H%M%S";
QString timeStr = formatTimeStr(timeFormat);
printf("开始采集:%s!\n", timeStr.toStdString().c_str());
m_iFrameCounter=0; m_iFrameCounter=0;
m_bRecordControl=true; m_bRecordControl=true;
m_imager.start();
m_baseFileName=baseFileName; m_baseFileName=baseFileName;
QString imageFileName=m_baseFileName+".bil"; std::cout << "曝光时间为:" << getExposureTime()/1000 << "ms" <<std::endl;
QString timesFileName=m_baseFileName+".times";
//
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
using namespace std; using namespace std;
ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream"); // ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
int number_WriteDisk = 100;
writeData2Disk->setParm(q, m_qFrameCounter,m_baseFileName,m_iFrameSizeInByte, number_WriteDisk, m_pool, m_rgbImage);
emit startWriteDiskSignal();
int indexofbuff;
DataBuffer * buffer;
QString timesFileName=m_baseFileName+".times";
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
// ofstream timesFile(timesFileName.toStdString());
double timeDifferenceBetweenSbgAndXimea;
double * sbgTimeBuffer = new double[number_WriteDisk];
m_imager.start();
struct timeval timeStart, timeEnd; struct timeval timeStart, timeEnd;
double runTime=0; double runTime=0;
gettimeofday(&timeStart, NULL); gettimeofday(&timeStart, NULL);
while (m_bRecordControl) while (m_bRecordControl)
{ {
unsigned short *x=m_imager.get_frame(m_buffer); unsigned short *x=m_imager.get_frame(m_buffer);
//fwrite(m_buffer,2,getBandCount()*getSampleCount(),hFile);
fwrite(m_buffer,1,m_iFrameSizeInByte,hFile);//*********************************
//fflush(hFile);//只保证了将IO缓冲写入系统缓冲中使IO读操作能成功但系统什么时候写入磁盘由系统决定一般是达到一定量时系统他就写入磁盘。
//sync();//强制系统将系统文件缓冲的内容写入磁盘
m_iFrameCounter+=1; m_iFrameCounter+=1;
// if(m_iFrameCounter==100) if (m_iFrameCounter == 1)
// break; {
timeDifferenceBetweenSbgAndXimea = calculateTimeDifferenceBetweenSbgAndximea(&m_imager.m_image, TimeDifferenceBetweensOSAndSbg);
double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg);
fprintf(hHimesFile,"%f\n",sbgTime);
//fwrite(&sbgTime,sizeof(double),1,hHimesFile);
timesFileHandle << sbgTime << "\n";
// std::cout<<"XimeaImager::startRecord---std::cout: "<<sbgTime<<std::endl;
// //用于测试是否漏帧
// if(m_iFrameCounter==getFramerate()*20)
// {
// break;
// }
// unsigned char pixel = *(unsigned char*)image.bp;//Default value: XI_MONO8
// unsigned short pixel =*(unsigned short*)image.bp;//XI_RAW16
// printf("Image %d (%dx%d) received from camera. First pixel value: %d\n", m_iFrameCounter, (int)image.width, (int)image.height, pixel);
} }
indexofbuff = m_iFrameCounter % number_WriteDisk;
if (indexofbuff == 1)
{
r_qtx.lock();
buffer = m_pool->newElement();
r_qtx.unlock();
}
if (indexofbuff == 0)
{
memcpy((void *)buffer->data + (number_WriteDisk - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
sbgTimeBuffer[number_WriteDisk - 1] = getSbgTime(&m_imager.m_image, timeDifferenceBetweenSbgAndXimea);
}
else
{
memcpy((void *)buffer->data + (indexofbuff - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
sbgTimeBuffer[indexofbuff - 1] = getSbgTime(&m_imager.m_image, timeDifferenceBetweenSbgAndXimea);
}
if (indexofbuff == 0)
{
r_qtx.lock();
q->push(buffer);
m_qFrameCounter->push(number_WriteDisk);
r_qtx.unlock();
for (int i = 0; i < number_WriteDisk; ++i)
{
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
}
}
}
if (indexofbuff != 0)
{
r_qtx.lock();
q->push(buffer);
m_qFrameCounter->push(indexofbuff);
r_qtx.unlock();
for (int i = 0; i < indexofbuff; ++i)
{
fprintf(hHimesFile,"%f\n",sbgTimeBuffer[i]);
}
std::cout << "没凑满: " << indexofbuff <<std::endl;
}
gettimeofday(&timeEnd, NULL); gettimeofday(&timeEnd, NULL);
runTime = (timeEnd.tv_sec - timeStart.tv_sec ) + (double)(timeEnd.tv_usec -timeStart.tv_usec)/1000000; runTime = (timeEnd.tv_sec - timeStart.tv_sec ) + (double)(timeEnd.tv_usec -timeStart.tv_usec)/1000000;
m_imager.stop();
writeData2Disk->exitWriteData2Disk();
writeHdr();
delete[] sbgTimeBuffer;
double frameInTheory=runTime * getFramerate(); double frameInTheory=runTime * getFramerate();
double frameLossed=frameInTheory - m_iFrameCounter;
double frameLossRate=frameLossed / frameInTheory;
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl; double frameLossed = m_imager.m_image.acq_nframe - m_iFrameCounter;
double frameLossRate = frameLossed / m_imager.m_image.acq_nframe;
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<< ".bil" <<std::endl;
std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl; std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl;
std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<std::endl; std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<std::endl;
std::cout<<"每秒数据量为: "<<getFramerate()*m_iFrameSizeInByte/(1024*1024)<<"MB"<<std::endl; std::cout<<"每秒数据量为: "<<getFramerate()*m_iFrameSizeInByte/(1024*1024)<<"MB"<<std::endl;
std::cout<<"理论采集帧数为: "<<frameInTheory<<std::endl; std::cout<<"理论采集帧数为: "<<m_imager.m_image.acq_nframe<<std::endl;
std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl; std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl;
std::cout<<"丢失帧数为: "<<frameLossed<<std::endl; std::cout<<"丢失帧数为: "<<frameLossed<<std::endl;
std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl; std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl;
fclose(hFile);
fclose(hHimesFile); fclose(hHimesFile);
timesFileHandle.close(); // timesFileHandle.close();
// timesFile.close();
printf("Stopping acquisition...\n"); timeStr = formatTimeStr(timeFormat);
m_imager.stop(); printf("停止采集:%s!\n", timeStr.toStdString().c_str());
writeHdr();
m_iImagerState=m_iImagerStateTemp; m_iImagerState=m_iImagerStateTemp;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
@ -532,6 +676,11 @@ void XimeaImager::writeHdr()
ofstream hdrFileHandle(hdrPath.toStdString()); ofstream hdrFileHandle(hdrPath.toStdString());
hdrFileHandle << "ENVI\n"; hdrFileHandle << "ENVI\n";
QString SN;
m_configfile.getSN(SN);
hdrFileHandle << "SN = " << SN.toStdString() << "\n";
hdrFileHandle << "interleave = bil\n"; hdrFileHandle << "interleave = bil\n";
hdrFileHandle << "byte order = 0\n"; hdrFileHandle << "byte order = 0\n";
hdrFileHandle << "data type = 2\n"; hdrFileHandle << "data type = 2\n";
@ -551,6 +700,9 @@ void XimeaImager::writeHdr()
hdrFileHandle << "wavelength units = nanometers\n"; hdrFileHandle << "wavelength units = nanometers\n";
hdrFileHandle << "wavelength = {"; hdrFileHandle << "wavelength = {";
//hdrFileHandle << std::setprecision(5); //hdrFileHandle << std::setprecision(5);
if (m_imager.getSpectralBin() == 1)
{
for (int i = getWindowStartBand(); i < getWindowEndBand(); i++) for (int i = getWindowStartBand(); i < getWindowEndBand(); i++)
{ {
hdrFileHandle << geWavelengthAtBand(i); hdrFileHandle << geWavelengthAtBand(i);
@ -561,6 +713,30 @@ void XimeaImager::writeHdr()
printf("头文件中写入了多少个波段:%d\n",i-getWindowStartBand()+1);//??????????????? printf("头文件中写入了多少个波段:%d\n",i-getWindowStartBand()+1);//???????????????
} }
} }
}
else if (m_imager.getSpectralBin() == 2)
{
int counter = 0;
for (int i = m_iOffsetyOfSpectralBin2; i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2; i++)
{
if (i*2 + 1 > m_iOffsetyOfSpectralBin1 + m_iHeightOfSpectralBin1)
{
printf("XimeaImager::writeHdr 出现错误:窗口中,光谱 bin1 波段数小于 bin2 的 2 倍。\n");
break;
}
hdrFileHandle << (geWavelengthAtBand(i*2) + geWavelengthAtBand(i*2 + 1)) / 2;
counter++;
if (i < m_iOffsetyOfSpectralBin2 + m_iHeightOfSpectralBin2 - 1)
hdrFileHandle << ", ";
else
{
printf("头文件中写入了多少个波段:%d\n", counter);
}
}
}
hdrFileHandle << "}\n"; hdrFileHandle << "}\n";
hdrFileHandle.close(); hdrFileHandle.close();
} }
@ -639,6 +815,18 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
m_iImagerState=xiApiErrorCodes; m_iImagerState=xiApiErrorCodes;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
break;
case 10:
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Timeout!"<<std::endl;
m_iImagerState=xiApiErrorCodes;
emit ximeaImageStatus(m_iImagerState);
break;
case 11:
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Invalid arguments supplied!"<<std::endl;
m_iImagerState=xiApiErrorCodes;
emit ximeaImageStatus(m_iImagerState);
break; break;
case 12: case 12:
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Not supported!"<<std::endl; std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Not supported!"<<std::endl;
@ -665,19 +853,26 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
break; break;
default: default:
QString ximeaError="ximeaError.txt";
ofstream ximeaErrorFile(ximeaError.toStdString().c_str(),ios::app);
ximeaErrorFile<< xiApiErrorCodes << "\n";
ximeaErrorFile.close();
m_iImagerState=99; m_iImagerState=99;
emit ximeaImageStatus(m_iImagerState); emit ximeaImageStatus(m_iImagerState);
break; break;
} }
writeXiApiErrorCodes("/media/nvme/300TC/ximeaError.txt", xiApiErrorCodes);
}
void XimeaImager::writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes)
{
ofstream ximeaErrorFile(filePath.toStdString().c_str(),ios::app);
char * timeFormat="%Y%m%d_%H%M%S";
QString timeStr = formatTimeStr(timeFormat);
ximeaErrorFile<< timeStr.toStdString().c_str() << ": " << xiApiErrorCodes << "\n";
std::cout<<"XimeaImager::writeXiApiErrorCodes-----------:xiApiErrorCodes: "<<timeStr.toStdString().c_str()<< ": " << xiApiErrorCodes<<std::endl;
ximeaErrorFile.close();
} }
void XimeaImager::stopRecord() void XimeaImager::stopRecord()
@ -691,6 +886,14 @@ int XimeaImager::getFrameCounter()
return m_iFrameCounter; return m_iFrameCounter;
} }
DataBuffer::DataBuffer()
{
}
DataBuffer::~DataBuffer()
{
}
RecordXimeaTemperature::RecordXimeaTemperature(Iris::IrisXimeaImager * imager) RecordXimeaTemperature::RecordXimeaTemperature(Iris::IrisXimeaImager * imager)
{ {
m_imager = imager; m_imager = imager;
@ -726,3 +929,88 @@ void RecordXimeaTemperature::recordTemperature(QString filePath= nullptr)
ximeaTemperatureFile.close(); ximeaTemperatureFile.close();
} }
WriteData2Disk::WriteData2Disk()
{
isExitWriteData2Disk = false;
}
void WriteData2Disk::write2Disk()
{
QString imageFileName=m_QbaseFileName+".bil";
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
int frameCounter = 0;
int frameNumber;
unsigned short * dataBuffer = new unsigned short[m_iFrameSizeInByte/2*m_iNumber_WriteDisk];
isExitWriteData2Disk = false;
while(true)
{
r_qtx.lock();
bool bempty=m_q->empty();
r_qtx.unlock();
if(bempty && isExitWriteData2Disk)
{
std::cout<<"WriteData2Disk::write2Disk-----------------------队列为空,采集线程已经退出!"<<std::endl;
break;
}
else if(isExitWriteData2Disk)
{
std::cout<<"WriteData2Disk::write2Disk-----------------------isExitWriteData2Disktrue"<<std::endl;
std::cout<<"WriteData2Disk::write2Disk-----------------------队列大小"<<m_q->size()<<std::endl;
}
else if(bempty && !isExitWriteData2Disk)
{
continue;
}
r_qtx.lock();
DataBuffer * buffer = m_q->front();
int frameNumber = m_qFrameCounter->front();
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte*frameNumber);
// m_pool->destroy(m_q->front());
m_pool->deleteElement(buffer);
m_q->pop();
m_qFrameCounter->pop();
r_qtx.unlock();
//构造rgb图像用于推流到m300遥控器
// m_rgbImage->FillRgbImage(dataBuffer);
// std::cout<<"WriteData2Disk::write2Disk-----------------------正在写磁盘!" << m_pool->max_size() <<std::endl;//
fwrite(dataBuffer,1,m_iFrameSizeInByte*frameNumber, hFile);
frameCounter++;
}
m_rgbImage->m_VideoWriter.release();
fclose(hFile);
delete[] dataBuffer;
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,内存池可达到的最多元素数:" << m_pool->max_size() <<std::endl;
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出fwrite 调用次数:" << frameCounter <<std::endl;
}
void WriteData2Disk::exitWriteData2Disk()
{
std::cout<< "执行函数WriteData2Disk::exitWriteData2Disk" <<std::endl;
isExitWriteData2Disk = true;
}
void WriteData2Disk::setParm(queue<DataBuffer *> * q, queue<int> * qFrameCounter, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
{
m_q = q;
m_qFrameCounter = qFrameCounter;
m_QbaseFileName = baseFileName;
m_iFrameSizeInByte = frameSizeInByte;
m_iNumber_WriteDisk = number_WriteDisk;
m_pool = pool;
m_rgbImage = rgbImage;
}