Click here to Skip to main content
15,886,761 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Use Modeless Dialog inside MFC DLL Pin
Andraw Tang23-Mar-11 2:40
Andraw Tang23-Mar-11 2:40 
AnswerRe: Use Modeless Dialog inside MFC DLL Pin
Hans Dietrich22-Mar-11 14:16
mentorHans Dietrich22-Mar-11 14:16 
GeneralRe: Use Modeless Dialog inside MFC DLL Pin
Andraw Tang23-Mar-11 2:41
Andraw Tang23-Mar-11 2:41 
AnswerRe: Use Modeless Dialog inside MFC DLL Pin
Nitheesh George22-Mar-11 23:04
Nitheesh George22-Mar-11 23:04 
GeneralRe: Use Modeless Dialog inside MFC DLL Pin
Andraw Tang23-Mar-11 2:42
Andraw Tang23-Mar-11 2:42 
Questionconvert an image (black & white) to a file (zero & one) in the VC++ Pin
Shatha8822-Mar-11 9:08
Shatha8822-Mar-11 9:08 
AnswerRe: convert an image (black & white) to a file (zero & one) in the VC++ Pin
Niklas L22-Mar-11 20:43
Niklas L22-Mar-11 20:43 
GeneralRe: convert an image (black & white) to a file (zero & one) in the VC++ Pin
Shatha8823-Mar-11 9:02
Shatha8823-Mar-11 9:02 
Well
I want to convert the (JPG )image to (0`s & 1`s)text file and
I used this code from internet and gave me this file, but not 0 and 1 also does not draw my picture Frown | :(
#include<iostream>
using namespace std;
#include<stdio.h>
#include<fstream>
#include <cv.h>
#include <highgui.h>
/*
Function takes OpenCV image as input and dumps its pixels to a file specified by filename in function arguments.
*/
int WritePixelsToFile(IplImage *img,const char *filename)
{
  /*open a file in text mode with write permissions.*/
 //FILE *file = fopen(filename, "wt");
 ofstream file;
  file.open (filename, ios::out);

 if(file==NULL)
 {
  /*If unable to open the specified file display error and return.*/
  perror("Unable to open specified file");
  return -1;
  }
  int i,j;
  CvScalar s;
  CvSize size=cvGetSize(img);
  for(i=0;i< size.height;i++)
     {
      for(j=0;j< size.width;j++)
        {
         s=cvGet2D(img,i,j); // get the (i,j) pixel value
        // fprintf (file,"%f\t",s.val[0]); // dump the (i,j) pixel value in file 
      file << s.val[0];  
	  }                         
      //fprintf(file,"\n");//write new line in file to seperate rows.         
      file <<"\n";  
  }
     /*release the file pointer.*/
file.close();

 return 1;
} 

int main ()
{
//ofstream o("C:\\file1.txt");
char name []= "C:\\file1.txt";
	IplImage *imgI = cvLoadImage("C:\\org.jpg");
	IplImage *dst = cvCreateImage( cvSize( 30, 30 ), IPL_DEPTH_8U, 1 );
/* CV_RGB2GRAY: convert RGB image to grayscale */
cvCvtColor( imgI, dst, CV_RGB2GRAY );
IplImage *binary= cvCreateImage( cvSize( 30, 30 ), IPL_DEPTH_8U, 1 );
cvThreshold(dst, binary, 150, 255, CV_THRESH_BINARY);
cvSaveImage("C:\\ooo.jpg",binary);

	WritePixelsToFile(binary,name );


	return 0;
}

the output will be
"

255252253245254252254255241248255255255255255254255249255252255231254255246246255248254255
25323024725523525525522725524921014791656572100127220253217255230252255243242251253232
25524425525124725124925516365042480701035151232251254237255255244255243
25225524423825524321369067000451410200033186251247253255247254255
2532382452532322065221326102167185181182169831667141146255253226255237255
24825525524621000110121233255244249255247246255254142230016126255235249252243
2552552522191653325233244255255255254252252241255250236222681030187254243255251
25524425452218292482422542532402392552552542552462472522552307341217232255240252
24625515831102212532552552552552552552552552482552322552552532204420124245254255
255242553214023825025525525525525525525525524525524225525425325516241039224243255
2502000132624025025525525525525525525525525525425224725524924525524863210169246254
2431406129525525325425525525525525525525525525524924625025424824325515121086255255
2558214016925525524225525525525525525525525525424825024825525524125421001628255255
2555210019625025425525525525525525525525525524825425525025325524625424415023248248
2504710419824625125525525525525525525525525525225525525324824625325225526025239248
2554954208255251244255255255255255255255255255253244255255253255253254008237255
255649251762532552412502552482422522552552552532422552482512552442552170831255255
242113501372522422552542532552552552472472552532482552472402532542491815962255255
255186022422392552472522412422472472522552492492552522552552472442537290142254250
23825314143162249244255255255251246255255236249255252255244250255196150219249245
25123211850492322552342452552552492512542492532442522492182552437412071242255255
2442552081517383254255250236241254248245255251254244255255227119501196245255248
2522492391462100116235255254242255255239252250255245244239125252107255254249238
25524825525510225005719525524025025524825525523425520078140468255238255237249
2542332402552151082301138216823324725524122718795103471252252254255255255
2362552552372552551582503240227484170110141086252252253254255255255
255255253249252251234212107160717061702111059189248255252253254255255255
2462502522512522552552552532191515517180650141223255255244240253253254255255255
238254255251253255253232238230241255255245247255255242240253255255255251253254255255255254
255253255255240225239255255255239248250255252255253247249255251226238247254254255255255254


"

and my picture is image : Black circle ,size = 30 × 30 pixels

can you help me
AnswerRe: convert an image (black & white) to a file (zero & one) in the VC++ Pin
Cedric Moonen22-Mar-11 21:26
Cedric Moonen22-Mar-11 21:26 
QuestionHow to use structure constructor ? Pin
_Flaviu22-Mar-11 6:58
_Flaviu22-Mar-11 6:58 
AnswerRe: How to use structure constructor ? Pin
Ozer Karaagac22-Mar-11 7:57
professionalOzer Karaagac22-Mar-11 7:57 
GeneralRe: How to use structure constructor ? Pin
_Flaviu22-Mar-11 8:39
_Flaviu22-Mar-11 8:39 
GeneralRe: How to use structure constructor ? Pin
Stefan_Lang23-Mar-11 0:06
Stefan_Lang23-Mar-11 0:06 
QuestionwaveOutOpen Working Properly but Voice is Low Pin
AmbiguousName22-Mar-11 2:36
AmbiguousName22-Mar-11 2:36 
AnswerRe: waveOutOpen Working Properly but Voice is Low Pin
rp_suman22-Mar-11 23:11
rp_suman22-Mar-11 23:11 
QuestionCLSID for invisible Pin
sarfaraznawaz22-Mar-11 1:24
sarfaraznawaz22-Mar-11 1:24 
AnswerRe: CLSID for invisible Pin
Richard MacCutchan22-Mar-11 5:15
mveRichard MacCutchan22-Mar-11 5:15 
QuestionOpenPrinter() API Pin
msr_codeproject21-Mar-11 22:41
msr_codeproject21-Mar-11 22:41 
AnswerRe: OpenPrinter() API Pin
Richard MacCutchan21-Mar-11 23:57
mveRichard MacCutchan21-Mar-11 23:57 
QuestionMFC: How to set the focus to the previously focused window? Pin
Erik21-Mar-11 19:48
Erik21-Mar-11 19:48 
AnswerRe: MFC: How to set the focus to the previously focused window? Pin
tagopi21-Mar-11 22:16
tagopi21-Mar-11 22:16 
GeneralRe: MFC: How to set the focus to the previously focused window? Pin
msr_codeproject21-Mar-11 22:32
msr_codeproject21-Mar-11 22:32 
AnswerRe: MFC: How to set the focus to the previously focused window? Pin
Hans Dietrich22-Mar-11 4:24
mentorHans Dietrich22-Mar-11 4:24 
GeneralRe: MFC: How to set the focus to the previously focused window? Pin
Emilio Garavaglia22-Mar-11 22:20
Emilio Garavaglia22-Mar-11 22:20 
QuestionHandle Inheritance in Windows [modified] Pin
Sudhan Gandhi21-Mar-11 0:59
Sudhan Gandhi21-Mar-11 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.