0
我在这个论坛上写了一个问题,希望能帮助我解决这个花费很多时间的问题,我用systemC写我的第一个程序,我的程序调试但运行异常我会尽我所能地扩展我的目标,我在两个不同的文本文件中存储了图像像素值的2个矩阵,我编写了一个加载两个矩阵和comapre它们的systemC代码,如果代码显示消息(运动)的阈值不同的优先级的数目。我的第一个程序系统C
我的代码由两个模块组成,第一个模块检查文本文件中是否有数字,如果是这个模块会自动让其他模块加载两个矩阵并进行比较,我真的需要这个代码用于我的项目毕业任何帮助或建议。
#include "systemc.h"
#include "stdio.h"
#define _CRT_SECURE_NO_WARNINGS
SC_MODULE(synchronous) {
sc_out<bool> in;
SC_CTOR(synchronous)
{}
void verify() {
FILE *ifp, *ofp;
char *mode = "r";
char outputFilename[] = "F:/yosri.txt";
int val;
ifp = fopen(outputFilename, mode);
while (fscanf_s(ifp, "%d", &val) != 1)
{
cout << " waiting...";
}
in = true;
}
};
SC_MODULE(imageProcess)
{
sc_in<bool> in;
SC_CTOR(imageProcess)
{
SC_METHOD(MotionDetection);
sensitive<<in;
}
void MotionDetection()
{
int Threshold = 20;
bool fileFound;
char *mode1 = "r";
char *mode2 = "w";
FILE *ofp1 = fopen("F:/image1.txt", mode1);
FILE *ofp2 = fopen("F:/images2.txt", mode1);
FILE *Motion = fopen("F:/image3.txt", mode2);
int rowCounter, colCounter, isEqual = 0;
int firstMatrix[384][512], secondMatrix[384][512];
// if (!(ofp1 || ofp2))
//{
//printf("2222222222222222222");
//fileFound = false;
//}
//else fileFound = true;
//if (fileFound) {
while (!feof(ofp1) && !feof(ofp2))
{
for (rowCounter = 0; rowCounter < 384; rowCounter++) {
for (colCounter = 0; colCounter < 512; colCounter++) {
scanf("%d", &firstMatrix[rowCounter][colCounter]);
}
}
for (rowCounter = 0; rowCounter < 384; rowCounter++)
{
for (colCounter = 0; colCounter < 512; colCounter++)
{
scanf("%d", &secondMatrix[rowCounter][colCounter]);
if (firstMatrix[rowCounter][colCounter] !=
secondMatrix[rowCounter][colCounter])
{
isEqual++;
break;
}
}
}
if (isEqual > Threshold)
{
fputc(secondMatrix[rowCounter][colCounter], Motion);
}
else cout<< "MOTION";
}
cout << "%d", isEqual;
}
};
// sc_main in top level function like in C++ main
int sc_main(int argc, char* argv[]) {
sc_start();
synchronous yosri("A");
yosri.verify();
imageProcess go("B");
go.MotionDetection();
return(0);
}