Bonjour je dois faire un encodeur prenant une image grayscale en entrée et l'ajouter a un message binaire. mo image de sortie cache bien mon message mais j'ai de l'overflow(debordement) et je ne comprends pas pourquoi.

Merci de votre aide: ci dessous le code

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <cv.h>   	// open cv general include file
#include <highgui.h>	// open cv GUI include file
#include <iostream>	// standard C++ I/O
 
using namespace cv; // OpenCV API is in the C++ "cv" namespace
using namespace std;
 
int main( int argc, char** argv )
{
 
  Mat inputImg;;  // inputobject
  Mat msgImg;	 //msgobject
  Mat outputImg(Size (640,480),0);  //outputImg
  std::vector<int>params;
  const string windowName = "OPENCV: basic image display"; // window name
 
  // check that command line arguments are provided and image reads in OK
 
  if((argc == 4) && !(inputImg = imread( argv[1],  0)).empty())
    {
      // create window object
 
 
 
      // display image in window
 
 
 
		msgImg = imread( argv[2],0);
 
 
 
	  // inverted binary image
 
 
	  for(int i=0; i<msgImg.rows; i++)
	  {
		  for(int j=0; j<msgImg.cols; j++)
		  {
 
		  if(msgImg.at<uchar>(i,j)==255)
		  msgImg.at<uchar>(i,j)=0;
		  if(msgImg.at<uchar>(i,j)==0)
		  msgImg.at<uchar>(i,j)=1;
 
 
 
		  outputImg.at<uchar>(i,j) = inputImg.at<uchar>(i,j) + msgImg.at<uchar>(i,j);
		  if(outputImg.at<uchar>(i,j)>255)
			  outputImg.at<uchar>(i,j)=255;
		  if(outputImg.at<uchar>(i,j)<0)
			  outputImg.at<uchar>(i,j)=0;
		  }
	  }
 
	  imshow("Output image",outputImg);
 
	  imwrite(argv[3], outputImg, params);
 
      waitKey(0); 
 
      // all OK : main returns 0
 
      return 0;
    }
 
    // not OK : main returns -1
 
    return -1;
}