Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

Shatha88

@Shatha88
About
Posts
2
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • convert an image (black & white) to a file (zero & one) in the VC++
    S Shatha88

    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 :(

    #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 24625515831102212

    C / C++ / MFC c++ help tutorial question

  • convert an image (black & white) to a file (zero & one) in the VC++
    S Shatha88

    Hello everyone I have a graduation project and I need to know how to convert an image (black & white) to a file (zero & one) in the VC++ and OpenCv ? Or in other words how can Read image as a File ?? Can anyone help me :/

    C / C++ / MFC c++ help tutorial question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups