peakCentering bug: if a line is invalid, HSync is disabled, but data still output
This commit is contained in:
parent
1b7c1750f2
commit
8c780c8867
@ -86,6 +86,7 @@ void peakCentering(
|
||||
ap_uint<2> SM = 0b00;
|
||||
ap_uint<1> evenFlag = 0;
|
||||
ap_uint<5> pkRng_S, pkRng_E;
|
||||
ap_uint<1> outFlag = 0;
|
||||
for(int n = 0; n <= WinNum; n ++)
|
||||
{
|
||||
#pragma HLS LOOP_TRIPCOUNT min=3072 max=3072
|
||||
@ -99,6 +100,9 @@ void peakCentering(
|
||||
else
|
||||
InData = zeroData;
|
||||
|
||||
if(InData.LazerWinY == 0x07ac)
|
||||
int kkk = 1; //debug point
|
||||
|
||||
if(0 == i) //HSync
|
||||
{
|
||||
evenFlag = n%2;
|
||||
@ -109,7 +113,13 @@ void peakCentering(
|
||||
HSyncData_d1.LazerWinX = LazerWinX_d1 + pkCenter;
|
||||
|
||||
if ((n > 0) &&( linePk.len>0))
|
||||
{
|
||||
OutCenteringPnt.write(HSyncData_d1);
|
||||
outFlag = 1;
|
||||
}
|
||||
else
|
||||
outFlag = 0;
|
||||
|
||||
HSyncData_d1 = InData;
|
||||
LazerWinX_d1 = InData.LazerWinX - RGN_DATA_WIN_SIZE;
|
||||
|
||||
@ -280,7 +290,7 @@ void peakCentering(
|
||||
stmOut.Sync = 0b00;
|
||||
stmOut.LazerWinX(7,0) = out_0;
|
||||
stmOut.LazerWinY(7,0) = out_1;
|
||||
if( (n > 0 ) && (pkCenter > 0) )
|
||||
if( (n > 0 ) && (pkCenter > 0) &&(outFlag == 1))
|
||||
{
|
||||
OutCenteringPnt.write(stmOut);
|
||||
}
|
||||
|
||||
@ -18,17 +18,17 @@ void save_bmp_2(
|
||||
fopen_s(&file, filename, "wb");
|
||||
#endif
|
||||
if (!file) {
|
||||
printf("无法打开文件 %s\n", filename);
|
||||
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> %s\n", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算每行填充字节数
|
||||
int bytes_per_row = RGN_DATA_WIN_SIZE * 3; // 每个像素3字节(BGR)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
|
||||
int bytes_per_row = RGN_DATA_WIN_SIZE * 3; // ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD>ֽڣ<EFBFBD>BGR<EFBFBD><EFBFBD>
|
||||
int padding = (4 - (bytes_per_row % 4)) % 4;
|
||||
int row_size = bytes_per_row + padding;
|
||||
int height = testSamples.size();
|
||||
|
||||
// 初始化文件头
|
||||
// <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ͷ
|
||||
BMPFileHeader file_header = {
|
||||
.file_type = 0x4D42, // 'BM'
|
||||
.file_size = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader) + row_size * height,
|
||||
@ -36,11 +36,11 @@ void save_bmp_2(
|
||||
.reserved2 = 0,
|
||||
.offset_data = sizeof(BMPFileHeader) + sizeof(BMPInfoHeader)
|
||||
};
|
||||
// 初始化信息头
|
||||
// <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣͷ
|
||||
BMPInfoHeader info_header = {
|
||||
.size = sizeof(BMPInfoHeader),
|
||||
.width = RGN_DATA_WIN_SIZE,
|
||||
.height = height, // 正数表示像素数据从下到上排列
|
||||
.height = height, // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.planes = 1,
|
||||
.bit_count = 24,
|
||||
.compression = 0,
|
||||
@ -51,21 +51,21 @@ void save_bmp_2(
|
||||
.colors_important = 0
|
||||
};
|
||||
|
||||
// 写入头信息
|
||||
// д<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>Ϣ
|
||||
fwrite(&file_header, 1, sizeof(BMPFileHeader), file);
|
||||
fwrite(&info_header, 1, sizeof(BMPInfoHeader), file);
|
||||
|
||||
// 写入像素数据(从最后一行开始)
|
||||
// д<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>п<EFBFBD>ʼ<EFBFBD><EFBFBD>
|
||||
uint8_t padding_bytes[3] = { 0, 0, 0 };
|
||||
for (int y = height - 1; y >= 0; y--) {
|
||||
for (int x = 0; x < RGN_DATA_WIN_SIZE; x++) {
|
||||
uint8_t pixel = (uint8_t)testSamples[y].data[x];
|
||||
// 将RGB转为BGR顺序
|
||||
// <EFBFBD><EFBFBD>RGBתΪBGR˳<EFBFBD><EFBFBD>
|
||||
fputc(pixel, file); // B
|
||||
fputc(pixel, file); // G
|
||||
fputc(pixel, file); // R
|
||||
}
|
||||
fwrite(padding_bytes, 1, padding, file); // 填充
|
||||
fwrite(padding_bytes, 1, padding, file); // <EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
@ -263,6 +263,9 @@ void convertStreamToArray(
|
||||
Luma_rgnData a_line;
|
||||
a_line.WinRdx = (uint16_t)Hsync.LazerWinX;
|
||||
a_line.y = (uint16_t)Hsync.LazerWinY;
|
||||
if(a_line.y >= 1963)
|
||||
int kkk = 1; //debug point
|
||||
|
||||
a_line.Rid = (uint16_t)Hsync.LazerWinRid;
|
||||
a_line.Flag = (uint8_t)Hsync.LazerWinFlag;
|
||||
a_line.PeakRltvRdx = (uint8_t)Hsync.RltvRdx;
|
||||
@ -319,59 +322,81 @@ void writepeakCenteringData(
|
||||
|
||||
|
||||
|
||||
#define TST_GROUP 1
|
||||
#define TST_GROUP 3
|
||||
|
||||
int main()
|
||||
{
|
||||
#if defined(__linux__)
|
||||
const char* InDataPath[TST_GROUP] = {
|
||||
"/home/zengHQ/CamTestData/testSample/RgnPixData/testData.txt"
|
||||
"/home/zengHQ/CamTestData/testSample/PickRgn_C/PickRgn_Rslt/Txt/",
|
||||
"/home/zengHQ/CamTestData/Grp_0/PickRgn_C/PickRgn_Rslt/Txt/",
|
||||
"/home/zengHQ/CamTestData/Grp_1/PickRgn_C/PickRgn_Rslt/Txt/"
|
||||
};
|
||||
const char* OutDataPath[TST_GROUP] = {
|
||||
"/home/zengHQ/CamTestData/testSample/PkCentering/testData.txt"
|
||||
"/home/zengHQ/CamTestData/testSample/PkCentering/",
|
||||
"/home/zengHQ/CamTestData/Grp_0/PkCentering/",
|
||||
"/home/zengHQ/CamTestData/Grp_1/PkCentering/",
|
||||
};
|
||||
#else
|
||||
const char* InDataPath[TST_GROUP] = {
|
||||
"E:/CamTestData/testSample/RgnPixData/testData.txt"
|
||||
"E:/CamTestData/testSample/PickRgn_C/PickRgn_Rslt/Txt/",
|
||||
"E:/CamTestData/Grp_0/PickRgn_C/PickRgn_Rslt/Txt/",
|
||||
"E:/CamTestData/Grp_1/PickRgn_C/PickRgn_Rslt/Txt/"
|
||||
};
|
||||
const char* OutDataPath[TST_GROUP] = {
|
||||
"E:/CamTestData/testSample/PkCentering/testData.txt"
|
||||
"E:/CamTestData/testSample/PkCentering/",
|
||||
"E:/CamTestData/Grp_0/PkCentering/",
|
||||
"E:/CamTestData/Grp_1/PkCentering/",
|
||||
};
|
||||
#endif
|
||||
int testFileSize[TST_GROUP] = {1, 4, 4};
|
||||
|
||||
for(int n = 0; n < TST_GROUP; n ++)
|
||||
for(int n = 1; n < TST_GROUP; n ++)
|
||||
{
|
||||
int winSize = 0;
|
||||
std::vector<Luma_rgnData> testData = readTestFile(InDataPath[n], &winSize);
|
||||
//gen test stream
|
||||
hls::stream<RgnPix> inStream;
|
||||
uint32_t FrmNo = 0x1;
|
||||
uint32_t timeStamp = 0x2;
|
||||
uint32_t encInfo = 0x3;
|
||||
uint16_t frameROI_w = 0x100;
|
||||
uint16_t frameROI_h = 2048;
|
||||
uint16_t frameROI_x = 0;
|
||||
uint16_t frameROI_y = 0;
|
||||
genTestSream(testData, inStream, FrmNo, timeStamp, encInfo, frameROI_w, frameROI_h, frameROI_x, frameROI_y);
|
||||
int fileSize = testFileSize[n];
|
||||
for(int fi = 0; fi < fileSize; fi++)
|
||||
{
|
||||
char fileName[200];
|
||||
char outFileName[200];
|
||||
#if defined(__linux__)
|
||||
sprintf(fileName, "%s%d_L_verilog.txt", InDataPath[n], fi);
|
||||
sprintf(outFileName, "%s%d_L_pkCenter.txt", OutDataPath[n], fi);
|
||||
#else
|
||||
sprintf_s(fileName, "%s%d_L_verilog.txt", InDataPath[n], fi);
|
||||
sprintf_s(outFileName, "%s%d_L_pkCenter.txt", OutDataPath[n], fi);
|
||||
#endif
|
||||
std::vector<Luma_rgnData> testData = readTestFile(fileName, &winSize);
|
||||
//gen test stream
|
||||
hls::stream<RgnPix> inStream;
|
||||
uint32_t FrmNo = 0x1;
|
||||
uint32_t timeStamp = 0x2;
|
||||
uint32_t encInfo = 0x3;
|
||||
uint16_t frameROI_w = 0x100;
|
||||
uint16_t frameROI_h = 2048;
|
||||
uint16_t frameROI_x = 0;
|
||||
uint16_t frameROI_y = 0;
|
||||
genTestSream(testData, inStream, FrmNo, timeStamp, encInfo, frameROI_w, frameROI_h, frameROI_x, frameROI_y);
|
||||
|
||||
hls::stream<RgnPix> outStream;
|
||||
peakCentering(inStream,outStream);
|
||||
hls::stream<RgnPix> outStream;
|
||||
peakCentering(inStream,outStream);
|
||||
|
||||
std::vector<Luma_rgnData> outData;
|
||||
uint32_t outFrmNo, outTimeStamp, outEncInfo;
|
||||
uint16_t outROI_w,outROI_h, outROI_x,outROI_y;
|
||||
convertStreamToArray(
|
||||
outStream,
|
||||
outData,
|
||||
&outFrmNo,
|
||||
&outTimeStamp,
|
||||
&outEncInfo,
|
||||
&outROI_w,
|
||||
&outROI_h,
|
||||
&outROI_x,
|
||||
&outROI_y);
|
||||
std::vector<Luma_rgnData> outData;
|
||||
uint32_t outFrmNo, outTimeStamp, outEncInfo;
|
||||
uint16_t outROI_w,outROI_h, outROI_x,outROI_y;
|
||||
convertStreamToArray(
|
||||
outStream,
|
||||
outData,
|
||||
&outFrmNo,
|
||||
&outTimeStamp,
|
||||
&outEncInfo,
|
||||
&outROI_w,
|
||||
&outROI_h,
|
||||
&outROI_x,
|
||||
&outROI_y);
|
||||
|
||||
writepeakCenteringData(OutDataPath[n], outData);
|
||||
writepeakCenteringData(outFileName, outData);
|
||||
}
|
||||
}
|
||||
printf("done!\n");
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user