0
私は多くの時間がかかったこの問題を解決するための助けを求めて、systemCを使って私の最初のプログラムを書いて、プログラムのデバッグをして例外を実行しました。 、私は2つの別のテキストファイルに画像のピクセル値の2行列を格納し、私はSystemCコードを2つの行列とcomapreをロードする、しきい値の異なるコードの数がメッセージ(動き)を表示する場合。私の最初のプログラムsystemC
私のコードは2つのモジュールで構成されていますが、最初のモジュールはテキストファイルに数字があるかどうかをチェックし、そうであればこのモジュールは他のモジュールを自動化して2つのマトリックスをロードして比較します任意の助けや提案を卒業。
#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);
}