yosri ben salah Posted June 12, 2017 Report Share Posted June 12, 2017 I wrote in this forum asking for help to solve this problem that took ame a lot of my time,i write my first program using systemC, I will expain my aim as much as I can , I stored 2 matrix of pixel value of image in two different text files, I write a systemC code that load two matrix and apply somme of absolute difference, if number of different superior of a Threshold the code displays message (motion). My code composed of two modules, the first module check if there a number stored in a text file, if yes this Module will automates the other module to load the two matrix and compare them, I really need this code for my project graduation any help or suggestion. #include "systemC.h" #include "string.h" #include "stdio.h" #include"stdlib.h" #include <time.h> #include <math.h> /* fabs */ #include <fstream> #include <iostream> #include <fstream> using namespace std; #define _CRT_SECURE_NO_WARNINGS _CRT_SECURE_NO_WARNINGS double elapsed; int H = 0; int D = 0; int a, b; int in = false; int L = 0; char *mode1 = "r"; char *mode2 = "w"; int i, j, k; int rows1, cols1, rows2, cols2; bool fileFound = false; FILE *SwitchContext; FILE *image1; FILE *image2; FILE *image3; int sum = 0; clock_t start = clock(); SC_MODULE(synchronization) { sc_in<bool>sig ; SC_CTOR(synchronization) { SC_METHOD(synchroprocess) } void synchroprocess() { cout << "\n Running Automation"; SwitchContext = fopen("F:/SWITCH CONTEXT.txt", mode2); fscanf(SwitchContext, "%d", &L); while (L != 0) { cout << "waiting..."; } sig == true; } }; SC_MODULE(imageProcess) { sc_in<bool>sig; SC_CTOR(imageProcess) { SC_METHOD(MotionDetector) sensitive(sig); } void MotionDetector() { image3 = fopen("F:/image3.txt", mode2); do { char *mode1 = "r"; char *mode2 = "w"; image1 = fopen("F:/image1.txt", mode1); if (!image1) { printf("File Not Found!!\n"); fileFound = true; } else fileFound = false; } while (fileFound); do { image2 = fopen("F:/image2.txt", mode1); if (!image2) { printf("File Not Found!!\n"); fileFound = true; } else fileFound = false; } while (fileFound); rows1 = rows2 = 384; cols1 = cols2 = 512; int **mat1 = (int **)malloc(rows1 * sizeof(int*)); for (i = 0; i < rows1; i++) mat1[i] = (int *)malloc(cols1 * sizeof(int)); i = 0; int **mat2 = (int **)malloc(rows2 * sizeof(int*)); for (i = 0; i < rows2; i++) mat2[i] = (int *)malloc(cols2 * sizeof(int)); i = 0; while (!feof(image1)) { for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) fscanf(image1, "%d%", &mat1[i][j]); } } i = 0; j = 0; while (!feof(image2)) { for (i = 0; i < rows2; i++) { for (j = 0; j < cols2; j++) fscanf(image2, "%d%", &mat2[i][j]); } } i = 0; j = 0; printf("\n\n"); for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { a = abs(mat1[i][j] = mat2[i][j]); b = b + a; } } i = j = 0; D = b / 196608; if (D > 0.9) { printf("%d,&K"); printf("MOTION...DETECTED"); getchar(); sc_pause; for (i = 0; i < rows1; i++) { for (j = 0; j < cols1; j++) { fprintf(image3, "%d ", mat2[i][j]); } fprintf(image3, "\n"); } printf("\n Image Saved...."); std::ofstream mon_fichier("F:\toto.txt"); mon_fichier << elapsed << '\n'; } fclose(image1); fclose(image2); fclose(image3); clock_t end = clock(); elapsed = ((double)end - start) / CLOCKS_PER_SEC; printf("time is %f", elapsed); } }; int sc_main(int argc, char* argv[]) { imageProcess master("EE2"); master.MotionDetector(); sc_start(); return(0); } Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted June 12, 2017 Author Report Share Posted June 12, 2017 Quote Link to comment Share on other sites More sharing options...
yosri ben salah Posted June 12, 2017 Author Report Share Posted June 12, 2017 i want that the module that compares images do not process until it is enabled by the first module Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.