Home > Software engineering >  C calling matlab, mixed and image display in MFC
C calling matlab, mixed and image display in MFC

Time:10-17

Doing these days using c + + calling matlab program, and the result image using MFC to show that I'm in image processing, please everyone a great god give some advice, how should I change, can be displayed, thanks a lot! Below is my current code, and the error,

Void CIILView: : OnStripenoiseRemoval ()
{
//TODO: add the command handler code
CIILDoc * pDoc=GetDocument ();
PDib CImage *=pDoc - & gt; GetPDib ();
If (pDib - & gt; IsNull ())
return;
Int width=pDib - & gt; GetWidth ();
Int height=pDib - & gt; GetHeight ().
Int ichannels=pDib - & gt; GetBPP ()/8;
If (ichannels==3)
Im24to8 (pDib);//this function has been scheduled for 24 eight

McLInitializeApplication (NULL, 0);
//initialize the library
LibaInitialize ();

CImage imgin;
CImage imgout;
//byteImage imgin;//is there a problem???????
//byteImage imgout;
//imgin. Load (_T (" 1. JPG "));
Int pit=imgin. GetPitch ();//returns the size of image held by the number of bytes wide
Int h=imgin. GetHeight ();
Int. W=imgin GetWidth ();
//unsigned char * pImgin=(unsigned char *) imgin. GetPixelAddress (0, h - 1);
Imgout. Create (w, h, 8).
//unsigned char * pImgout=(unsigned char *) imgout. GetPixelAddress (0, h - 1);
Unsigned char * p1=(unsigned char *) imgin. GetBits ();//0-255 to return to the top left corner or the bottom left address
Unsigned char * p2=(unsigned char *) imgout. GetBits ();
Int bits=sizeof (unsigned char);//8 returns a byte
Unsigned char * pImgin=new unsigned char [8 w * h * * sizeof (unsigned char)];
Unsigned char * pImgout=new unsigned char [8 w * h * * sizeof (unsigned char)];
for (int i=0; i{
For (int j=0; J{
PImgin + j] [I * w=(p1 + j] [I * pit;//save the size of the input image data values
}
}
//create input mx string array
MwArray DataIn (w, h, mxUINT8_CLASS);
MwArray DataOut (w, h, mxUINT8_CLASS);
MwArray W (1, 1, mxUINT8_CLASS);
MwArray H (1, 1, mxUINT8_CLASS);

DataIn. SetData ((mxUint8 *) pImgin, w * h);
Baron etData (& amp; W, 1);
H.S etData (& amp; H, 1);
//demo function called
SolveV (1, DataOut, DataIn);/////this way there is no question of input and output parameters

DataOut. GetData ((mxUint8 *) pImgout, w * h);
for (int i=0; i{
For (int j=0; J{
The p2 [I * pit + j]=pImgout [I * w + j];
}
}


//PaletteChangedToGray (& amp; Imgout);
//imgout. Save (_T (" out. JPG "));
PDoc - & gt; PaletteChangedToGray (pDib);
PDoc - & gt; AddHistroyResult (pDib);
//FreebyteImageObj (imgin);
//FreebyteImageObj (imgout);
Invalidate (true);
}


I think I'm code written in a bit of a problem, and the error is

CodePudding user response:

See "matlab and c/c + + mixed programming" version 4 (out of)

CodePudding user response:

I just c + + calling matlab code, if just save save, the result is correct, just now I don't know how to use MFC to according to the results, thank you.

CodePudding user response:

Don't be A language code is modified to B language code busywork,
Also don't use A language code to directly invoke B language code base, this complicated things so easy to get wrong,
Just make A, B language code of input and output is redirected to A text file, or modify A, B language code let it through text file input and output,
Can easily make A, B coordination between the two languages,
For example:
A will request data written to A file a.t xt, renamed after finish aa. TXT
B find aa. TXT, read its contents, call the corresponding function, and writes the results file b.t xt, after finish delete aa. TXT, changed its name to bb. TXT
Found A bb. TXT, read the content, after finish delete bb. TXT
Above can be replaced by any kind of A language or development environment, B can be replaced by any kind of with the development of A different language or development environment,
Unless A or B does not support to determine whether A file exists, file read and write and file name,
But who can name does not support to determine whether a file exists, file read and write and file name for the development of language or development environment?
Can put the temporary files on the RamDisk efficiency decrease wear disk,
Data structure is very complex, a text file format problems refer to a json or XML

The communication methods between the temporary text file sharing this process there are plenty of advantages, compared to other method only listed below I can think of now:
Loose coupling between process,
Can be on the same machine, process, also can cross machine, across the operating system, hardware platform, and even multinational,
, convenient debugging, and monitoring, only let the third party or artificial view the temporary text files,
Switch, convenient online service, need to delete or create the temporary text files,
, is convenient to realize distributed and load balancing,
Services to provide convenient, queue, queue is full and it is almost impossible to happen (unless the hard disk space full)
DE...

"Across different languages, machine, across the operating system, hardware platform, multinational, cross *. *" this suffering,
back "exchange of information using Shared plain text file" shore!
  • Related