11 Commits

Author SHA1 Message Date
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
15 changed files with 1181 additions and 124 deletions

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.5.2)
project(ximeaAirborneSystem)
set(CMAKE_CXX_STANDARD 14)
@ -9,7 +9,7 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(QT Core Network SerialPort)
set(QT Core Network SerialPort Gui)
set(TEMPLATE app)
set(TARGET ximeaImageRecorder)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
@ -17,9 +17,12 @@ find_package(Qt5 REQUIRED ${QT})#
include_directories(.)
include_directories(/home/300tc/library/ximeaControlDll/Header_Files)
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}
Source_Files/fileoperation.cpp
Header_Files/fileoperation.h
@ -41,10 +44,13 @@ add_executable(${CMAKE_PROJECT_NAME}
Source_Files/ximeaimager.cpp
Header_Files/ximeaimager.h
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})
target_link_libraries(${CMAKE_PROJECT_NAME}
irisXimeaImager
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,12 +9,15 @@
#include <iomanip>
#include <cstdlib>
#include <libconfig.h++>
#include <string>
#include <QFileInfo>
#include <QString>
#include <QCoreApplication>
#include <QDir>
#include "utility_tc.h"
using namespace std;
using namespace libconfig;
@ -32,6 +35,10 @@ public:
bool getEffectiveWindow(int &width, int &offsetx, int &height, int &offsety);
bool getEffectiveWindowRoi(int &width, int &offsetx);
bool getGainOffset(float &gain, float &offset);
bool getSN(QString &SN);
bool getBufferPolicy(int &bufferPolicy);
bool getAcqBufferSize(int &acqBufferSize);
bool createConfigFile();
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 sbgAccuracySignal(int);
void sbgAccuracySignal(int, int);
};
}

View File

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

View File

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

View File

@ -25,6 +25,8 @@
#include <fstream>
#include <unistd.h>
#include <exception>
#include <fcntl.h>
#include <sys/mman.h>
#include <QObject>
#include <QDateTime>
@ -37,6 +39,13 @@
#include "math.h"
#include "utility_tc.h"
#include "MemoryPool.h"
#include <queue>
#include <QMutex>
#include "rgbImage.h"
//#ifdef WIN32
//#include <xiApi.h> // Windows
@ -44,6 +53,23 @@
//#include <m3api/xiApi.h> // Linux, OSX
//#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
{
Q_OBJECT
@ -64,16 +90,47 @@ 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, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage);
private:
queue<DataBuffer *> * m_q;
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
{
Q_OBJECT
public:
XimeaImager();
~XimeaImager();
void setFramerate(double framerate);
double getFramerate();
double setExposureTime(float exposureTime);
int wrapSetExposureTime(float exposureTime_in_us);
double getExposureTime();
double autoExposure();
void setGain(double gain);
@ -87,6 +144,7 @@ public:
void stopRecord();
int getFrameCounter();
void writeXiApiErrorCodes(QString filePath, int xiApiErrorCodes);
int getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel);
@ -99,14 +157,21 @@ private:
QThread * m_recordTempThread;
RecordXimeaTemperature * m_ximeaTemperature;
QThread * writeData2DiskThread;
WriteData2Disk * writeData2Disk;
queue<DataBuffer *> * q;
MemoryPool<DataBuffer> * m_pool;
QString m_baseFileName;
QString m_ximeaTemperatureCSVPath;
Iris::IrisXimeaImager m_imager;
unsigned short * m_buffer;
// MemoryPool<unsigned short> m_pool;
bool m_bRecordControl;
int m_iFrameCounter;
int m_iFrameSizeInByte;
rgbImage * m_rgbImage;
void writeHdr();
void processXiApiErrorCodes(int xiApiErrorCodes);
@ -132,6 +197,8 @@ private:
Configfile m_configfile;
public slots:
void openImger();
void closeImger();
@ -143,5 +210,9 @@ signals:
void ximeaImageStatus(int);
void recordXimeaTemperatureSignal(QString);
void startWriteDiskSignal();
void autoExposeMaxValueOfOneFrame(int, double);
void frameRateSignal(double);
};
#endif // XIMEAIMAGER_H

View File

@ -206,6 +206,66 @@ bool Configfile::getGainOffset(float &gain, float &offset)
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()
{
using namespace std;
@ -217,7 +277,7 @@ bool Configfile::createConfigFile()
// Add some settings to the configuration.
Setting &SN = root.add("SN", Setting::TypeString) = "0098";
Setting &spatialBin = root.add("spatialBin", Setting::TypeInt) = 1;
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);
@ -228,13 +288,13 @@ bool Configfile::createConfigFile()
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_spatial.add("width", Setting::TypeInt) = 1392;
effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 272;
effective_window_Bin1_spatial.add("width", Setting::TypeInt) = 1368;
effective_window_Bin1_spatial.add("offsetx", Setting::TypeInt) = 288;
effective_window_Bin1_Spectral.add("height", Setting::TypeInt) = 300;
effective_window_Bin1_Spectral.add("offsety", Setting::TypeInt) = 348;
effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 712;
effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 128;
effective_window_Bin2_spatial.add("width", Setting::TypeInt) = 688;
effective_window_Bin2_spatial.add("offsetx", Setting::TypeInt) = 144;
effective_window_Bin2_Spectral.add("height", Setting::TypeInt) = 150;
effective_window_Bin2_Spectral.add("offsety", Setting::TypeInt) = 174;
@ -263,10 +323,18 @@ bool Configfile::createConfigFile()
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.
QString output_file = QDir::cleanPath(QCoreApplication::applicationDirPath() + QDir::separator() + "ximea.cfg");
QString output_file = "/media/nvme/300TC/config/ximea.cfg";
try
{
QList<QString> fileInfo = getFileInfo(output_file);
bool ret = createDir(fileInfo[0]);
cfg.writeFile(output_file.toStdString().c_str());
cerr << "New configuration successfully written to: " << output_file.toStdString().c_str() << endl;

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 = "ttyUSB2";
QString portname = "ttyUSB0";
m_serial->setPortName(portname);
m_serial->open(QIODevice::ReadWrite);
@ -622,19 +622,19 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
switch (mode)
{
case SBG_ECOM_SOL_MODE_UNINITIALIZED:
std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl;
// std::cout<<"此刻模式为: "<<"UNINITIALIZED"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_VERTICAL_GYRO:
std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl;
// std::cout<<"此刻模式为: "<<"VERTICAL_GYRO"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_AHRS:
std::cout<<"此刻模式为: "<<"AHRS"<<std::endl;
// std::cout<<"此刻模式为: "<<"AHRS"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_NAV_VELOCITY:
std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl;
// std::cout<<"此刻模式为: "<<"NAV_VELOCITY"<<std::endl;
break;
case SBG_ECOM_SOL_MODE_NAV_POSITION:
std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl;
// std::cout<<"此刻模式为: "<<"NAV_POSITION"<<std::endl;
break;
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)
{
// std::cout<<"纬度精度为:"<<logData.gpsPosData.latitudeAccuracy<<std::endl;
float maximal=0;
float latitudeAccuracy=logData.gpsPosData.latitudeAccuracy;
float longitudeAccuracy=logData.gpsPosData.longitudeAccuracy;
float altitudeAccuracy=logData.gpsPosData.altitudeAccuracy;
int satelliteCounter=(int)logData.gpsPosData.numSvUsed;
if(latitudeAccuracy<longitudeAccuracy)
maximal = longitudeAccuracy;
@ -687,7 +685,10 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
if(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)
{
@ -710,15 +711,10 @@ void sbgtc::SbgRecorder::parseSbgMessage(QByteArray * sbgMessage)
char setGpsTimeCommand[256];
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;
}
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)
{
//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();
QString sbgFileName=m_baseFileName+".sbg";
QString sbgFileName=m_baseFileName+".bin";
FILE * fileHandle=fopen(sbgFileName.toStdString().c_str(),"w+b");
@ -802,7 +798,7 @@ void sbgtc::SbgRecorder::startRecordSbg()
while (m_bRecordControl)
{
//std::cout<<"SbgRecorder::startRecordSbg--------------:"<<std::endl;
if(m_serial->waitForReadyRead())
if(m_serial->waitForReadyRead(30000))
{
//requestData.resize(m_serial->size());
requestData = m_serial->readAll();

View File

@ -16,7 +16,7 @@ UdpServer::UdpServer()
m_RecordThread=new QThread();
m_imager=new XimeaImager();
m_imager->moveToThread(m_RecordThread);
m_RecordThread->start();
m_RecordThread->start(QThread::HighestPriority);
m_CopyFileThread=new QThread();
m_copyFile=new FileOperation();
@ -47,9 +47,11 @@ UdpServer::UdpServer()
connect(m_sbgRecorder, SIGNAL(serialPortStatus(int)),this, SLOT(sendSerialPortStatus(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(autoExposeMaxValueOfOneFrame(int, double)),this, SLOT(sendXimeaAutoExposeMaxValueOfOneFrame(int, double)));
connect(m_imager, SIGNAL(frameRateSignal(double)),this, SLOT(sendXimeaImageFrameRate(double)));
connect(m_copyFile, SIGNAL(copyFileStatus(int)),this, SLOT(sendCopyFileStatus(int)));
@ -122,26 +124,19 @@ void UdpServer::processPendingDatagrams()
}
case 3://系统开始采集高光谱影像
{
//emit startRecordHyperspectralSignal();//真实的影像开始采集通过惯导中的信号(sbgReady)触发
m_sbgRecorder->startRecordHyperspectral();
// if(m_sbgRecorder->getSbgState()==2)//开始采集前还需要判断相机的状态??????????????????????????????????????????
// {
// }
// else if(m_sbgRecorder->getSbgState()==3)
// {
// std::cout<<"系统已经开始采集!"<<std::endl;
// }
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
{
std::cout<<"3代表系统开始采集高光谱影像!"<<std::endl;
m_sbgRecorder->startRecordHyperspectral();
}
break;
}
case 4://系统停止采集高光谱影像
{
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=104)
{
std::cout<<"4代表系统停止采集高光谱影像!"<<std::endl;
m_imager->stopRecord();
}
@ -169,17 +164,11 @@ void UdpServer::processPendingDatagrams()
}
case 7:
{
if(datagramList[1].toInt()==1)
if(m_imager->getImagerState()>=101 && m_imager->getImagerState()<=103)
{
std::cout<<"拷贝数据!"<<std::endl;
emit startCopyFileSignal();
}
else if(datagramList[1].toInt()==0)
{
std::cout<<"删除数据!"<<std::endl;
emit startDeleteFileSignal();
float time = datagramList[1].toFloat();//ms
m_imager->wrapSetExposureTime(time*1000);
std::cout<<"7手动设置曝光时间为" << time <<std::endl;
}
break;
@ -260,9 +249,9 @@ void UdpServer::sender(int status)
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;
@ -274,7 +263,7 @@ void UdpServer::sendSerialPortStatus(int serialPortStatus)
void UdpServer::sendSbgSolutionModeState(int SolutionMode)
{
std::cout<<"UdpServer::sendSbgSolutionModeState---------------------:"<< SolutionMode <<std::endl;
// std::cout<<"UdpServer::sendSbgSolutionModeState---------------------:"<< SolutionMode <<std::endl;
QByteArray datagram2send;
@ -284,13 +273,13 @@ void UdpServer::sendSbgSolutionModeState(int SolutionMode)
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;
QByteArray datagram2send;
QString status = "Accuracy," + QString::number(Accuracy);
QString status = "Accuracy," + QString::number(Accuracy) + "," + QString::number(SatelliteCounter);
datagram2send.operator =(status.toStdString().c_str());
m_udpSocket->writeDatagram(datagram2send.data(),datagram2send.size(),m_clientIpAddress, 45455);
@ -298,7 +287,7 @@ void UdpServer::sendSbgAccuracyState(int Accuracy)
void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
{
std::cout<<"UdpServer::sendXimeaImageStatus---------------------:"<< ximeaImageStatus <<std::endl;
// std::cout<<"UdpServer::sendXimeaImageStatus---------------------:"<< ximeaImageStatus <<std::endl;
QByteArray datagram2send;
@ -308,9 +297,33 @@ void UdpServer::sendXimeaImageStatus(int ximeaImageStatus)
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::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)
{
std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl;
// std::cout<<"UdpServer::sendCopyFileStatus---------------------:"<< fileStatus <<std::endl;
QByteArray datagram2send;

View File

@ -1,6 +1,25 @@
#include "Header_Files/utility_tc.h"
#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()
{
using namespace std;
@ -69,3 +88,36 @@ void swap(unsigned short * a, unsigned short * b)
*a=*b;
*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,9 +7,7 @@ XimeaImager::XimeaImager()
m_iFrameCounter=0;
m_iImagerState=100;
//connect(this, SIGNAL(recordFinished()),this, SLOT());
QString ximeaCfgFile = QDir::cleanPath(QCoreApplication::applicationDirPath() + QDir::separator() + "ximea.cfg");
QString ximeaCfgFile = "/media/nvme/300TC/config/ximea.cfg";
m_configfile.setConfigfilePath(ximeaCfgFile.toStdString());
if(!m_configfile.isConfigfileExist())
m_configfile.createConfigFile();
@ -21,6 +19,22 @@ XimeaImager::XimeaImager()
m_recordTempThread->start();
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_rgbImage = new rgbImage();
}
XimeaImager::~XimeaImager()
{
}
void XimeaImager::openImger()
@ -61,13 +75,28 @@ void XimeaImager::openImger()
if (ret)
{
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;
}
int width_roi = 0, offsetx_roi = 0;
ret = m_configfile.getEffectiveWindowRoi(width_roi, offsetx_roi);
if (ret)
// int width_roi = 0, offsetx_roi = 0;
// ret = m_configfile.getEffectiveWindowRoi(width_roi, offsetx_roi);
// 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);
@ -77,6 +106,7 @@ void XimeaImager::openImger()
int frameSizeAuto = m_imager.getBufferSizeOfOneFrame();
m_iFrameSizeInByte = frameSizeAuto;
std::cout<<"每一帧的字节数:-------------------------------"<< m_iFrameSizeInByte <<std::endl;
m_buffer = new unsigned short[m_iFrameSizeInByte];
@ -140,6 +170,8 @@ void XimeaImager::setFramerate(double framerate)
m_iImagerState=102;
emit ximeaImageStatus(m_iImagerState);
emit frameRateSignal(framerate);
}
catch(int xiApiErrorCodes)
{
@ -196,6 +228,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 exposureTime;
@ -206,17 +256,20 @@ double XimeaImager::autoExposure()
float suitableMaxValue=4095 * 0.8;
double framerate = m_imager.get_framerate();
double maxExposureTime = 1/framerate*1000000;
double maxExposureTime = 1/framerate*1000000*0.95;//0.95目的:避免曝光时间超过最大,而造成帧率降低
exposureTime=setExposureTime(maxExposureTime);
bool bIsAutoExposureOk=false;
while(!bIsAutoExposureOk)
{
std::cout<<"自动曝光本次时间为:"<< exposureTime <<std::endl;
m_imager.start();
m_imager.get_frame(m_buffer);
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)
{
@ -251,6 +304,7 @@ double XimeaImager::autoExposure()
m_iImagerState=103;
emit ximeaImageStatus(m_iImagerState);
emit autoExposeMaxValueOfOneFrame(maxValueOfOneFrame, exposureTime/1000);
std::cout<<"自动曝光完成!"<<std::endl;
return exposureTime;
@ -408,7 +462,6 @@ int XimeaImager::getMaxValueOfOneFrame(unsigned short * data, int numberOfPixel)
int a=0;
}
}
printf("本帧最大值为: %d.\n",maxValue);
return maxValue;
}
@ -435,89 +488,111 @@ void XimeaImager::startRecord(double TimeDifferenceBetweensOSAndSbg,QString base
m_iImagerState=104;
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_bRecordControl=true;
m_imager.start();
m_baseFileName=baseFileName;
QString imageFileName=m_baseFileName+".bil";
QString timesFileName=m_baseFileName+".times";
//
FILE *hFile=fopen(imageFileName.toStdString().c_str(),"w+b");
QString timesFileName=m_baseFileName+".times";
FILE *hHimesFile=fopen(timesFileName.toStdString().c_str(),"w+");
// ofstream timesFile(timesFileName.toStdString());
std::cout << "曝光时间为:" << getExposureTime()/1000 << "ms" <<std::endl;
using namespace std;
ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
// ofstream timesFileHandle(timesFileName.toStdString()+"_ofstream");
int number_WriteDisk = 100;
writeData2Disk->setParm(q,m_baseFileName,m_iFrameSizeInByte, number_WriteDisk, m_pool, m_rgbImage);
emit startWriteDiskSignal();
int indexofbuff;
DataBuffer * buffer;
m_imager.start();
struct timeval timeStart, timeEnd;
double runTime=0;
gettimeofday(&timeStart, NULL);
while (m_bRecordControl)
{
unsigned short *x=m_imager.get_frame(m_buffer);
m_iFrameCounter+=1;
//fwrite(m_buffer,2,getBandCount()*getSampleCount(),hFile);
fwrite(m_buffer,1,m_iFrameSizeInByte,hFile);//*********************************
// fwrite(m_imager.m_image.bp,static_cast<int>(m_imager.m_image.bp_size),1,hFile);
//fflush(hFile);//只保证了将IO缓冲写入系统缓冲中使IO读操作能成功但系统什么时候写入磁盘由系统决定一般是达到一定量时系统他就写入磁盘。
//sync();//强制系统将系统文件缓冲的内容写入磁盘
m_iFrameCounter+=1;
// if(m_iFrameCounter==100)
// break;
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);
}
else
{
memcpy((void *)buffer->data + (indexofbuff - 1) * m_iFrameSizeInByte,m_imager.m_image.bp,m_iFrameSizeInByte);
}
if (indexofbuff == 0)
{
r_qtx.lock();
q->push(buffer);
r_qtx.unlock();
}
double sbgTime=getSbgTime(TimeDifferenceBetweensOSAndSbg);
fprintf(hHimesFile,"%f\n",sbgTime);
//fwrite(&sbgTime,sizeof(double),1,hHimesFile);
// fwrite(&sbgTime,sizeof(double),1,hHimesFile);
// timesFile<<sbgTime<< "\n";
timesFileHandle << sbgTime << "\n";
// std::cout<<"XimeaImager::startRecord---std::cout: "<<sbgTime<<std::endl;
// //用于测试是否漏帧
// if(m_iFrameCounter==getFramerate()*20)
// {
// break;
// }
// if(m_iFrameCounter/getFramerate() > 5*60) //这个判断会导致丢帧率的大幅升高5% → 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);
// timesFileHandle << sbgTime << "\n";
}
gettimeofday(&timeEnd, NULL);
runTime = (timeEnd.tv_sec - timeStart.tv_sec ) + (double)(timeEnd.tv_usec -timeStart.tv_usec)/1000000;
m_imager.stop();
writeData2Disk->exitWriteData2Disk();
double frameInTheory=runTime * getFramerate();
double frameLossed=frameInTheory - m_iFrameCounter;
double frameLossRate=frameLossed / frameInTheory;
m_iFrameCounter = m_iFrameCounter - indexofbuff;
if (indexofbuff != 0)
{
m_pool->deleteElement(buffer);
}
double frameInTheory=runTime * getFramerate() - indexofbuff;
double frameLossed=m_imager.m_image.acq_nframe - indexofbuff - m_iFrameCounter;
double frameLossRate=frameLossed / (m_imager.m_image.acq_nframe - indexofbuff);
std::cout<<"当前采集文件为: "<<baseFileName.toStdString()<<std::endl;
std::cout<<"采集时间为: "<<runTime<< "s" <<std::endl;
std::cout<<"当前帧率为: "<<getFramerate() << "hz" <<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 - indexofbuff<<std::endl;
std::cout<<"实际采集帧数为:"<<m_iFrameCounter<<std::endl;
std::cout<<"丢失帧数为: "<<frameLossed<<std::endl;
std::cout<<"丢帧率为: "<<frameLossRate * 100<< "%" <<std::endl;
fclose(hFile);
fclose(hHimesFile);
timesFileHandle.close();
// timesFileHandle.close();
// timesFile.close();
printf("Stopping acquisition...\n");
m_imager.stop();
timeStr = formatTimeStr(timeFormat);
printf("停止采集:%s!\n", timeStr.toStdString().c_str());
writeHdr();
@ -542,6 +617,11 @@ void XimeaImager::writeHdr()
ofstream hdrFileHandle(hdrPath.toStdString());
hdrFileHandle << "ENVI\n";
QString SN;
m_configfile.getSN(SN);
hdrFileHandle << "SN = " << SN.toStdString() << "\n";
hdrFileHandle << "interleave = bil\n";
hdrFileHandle << "byte order = 0\n";
hdrFileHandle << "data type = 2\n";
@ -649,6 +729,18 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
m_iImagerState=xiApiErrorCodes;
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;
case 12:
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:Not supported!"<<std::endl;
@ -675,20 +767,26 @@ void XimeaImager::processXiApiErrorCodes(int xiApiErrorCodes)
break;
default:
QString ximeaError="ximeaError.txt";
ofstream ximeaErrorFile(ximeaError.toStdString().c_str(),ios::app);
ximeaErrorFile<< xiApiErrorCodes << "\n";
std::cout<<"XimeaImager::processXiApiErrorCodes-----------:未处理ximea异常代码"<< xiApiErrorCodes <<std::endl;
ximeaErrorFile.close();
m_iImagerState=99;
emit ximeaImageStatus(m_iImagerState);
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()
@ -702,6 +800,14 @@ int XimeaImager::getFrameCounter()
return m_iFrameCounter;
}
DataBuffer::DataBuffer()
{
}
DataBuffer::~DataBuffer()
{
}
RecordXimeaTemperature::RecordXimeaTemperature(Iris::IrisXimeaImager * imager)
{
m_imager = imager;
@ -737,3 +843,72 @@ void RecordXimeaTemperature::recordTemperature(QString filePath= nullptr)
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;
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(bempty && !isExitWriteData2Disk)
{
continue;
}
r_qtx.lock();
DataBuffer * buffer = m_q->front();
memcpy(dataBuffer,buffer->data,m_iFrameSizeInByte*m_iNumber_WriteDisk);
// m_pool->destroy(m_q->front());
m_pool->deleteElement(buffer);
m_q->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*m_iNumber_WriteDisk, hFile);
frameCounter++;
}
m_rgbImage->m_VideoWriter.release();
fclose(hFile);
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,内存池可达到的最多元素数:" << m_pool->max_size() <<std::endl;
std::cout<<"WriteData2Disk::write2Disk-----------------------写磁盘线程将退出,共写帧数:" << frameCounter*m_iNumber_WriteDisk <<std::endl;
}
void WriteData2Disk::exitWriteData2Disk()
{
isExitWriteData2Disk = true;
}
void WriteData2Disk::setParm(queue<DataBuffer *> * q, QString baseFileName, int frameSizeInByte, int number_WriteDisk, MemoryPool<DataBuffer> * pool, rgbImage * rgbImage)
{
m_q = q;
m_QbaseFileName = baseFileName;
m_iFrameSizeInByte = frameSizeInByte;
m_iNumber_WriteDisk = number_WriteDisk;
m_pool = pool;
m_rgbImage = rgbImage;
}