Thread: If statement is been passed over-Simple Opencv project

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    18

    If statement is been passed over-Simple Opencv project

    I cant seem to hit these if statements my code seems to pass over them without altering the values I want. I cant seem to find the problem and the debugger wont hit them either as I run through the code.
    Im on windows 7 using visual studio 2010 if that helps.
    This is an openCV project to reconstruct an image based on a text file of 1s and 0s.
    Code:
    // reconstruction1.cpp : Defines the entry point for the console //application.
    //
    
    #include "stdafx.h"
    #include <stdio.h>
    #include <iostream>
    #include <cv.h>
    #include <cxcore.h>
    #include <highgui.h>
    #include <math.h>
    #include "cv.h"
    #include "highgui.h"
    #include "stdio.h"
    #include <fstream>
    using namespace std;
    
    
    
    int main ()
    {
    	//create a reconstruction function to take my output files,so far of 1 //and 0s and build an edge map
    
    
    	ifstream myfile;
    	myfile.open("me.txt");
    	int height=145,width=138;
    	//size of myimage
    	CvSize	a=cvSize(200,200);
    	//create my image for out put
    	IplImage* img=cvCreateImage(a,IPL_DEPTH_32F,4);
    	//create pixel
    	CvScalar pix;
    	int c,c2;
    
    	//makesure its open
    	if (myfile.is_open())
    	{
    	
    	cout<<"ok";
    
    	//create loop and count varibles
    	int c1,b1=0,w=0;
    	//start loop
    	while(w<=20010)
    	{
    		//this loops through every pixel starting at height width(h,w)
    		for(b1;b1<=height-1;b1++)
    		{
    		 for(c1=0;c1<=width-1;c1++)
    		 {
    			 //get next charecter in file, it will be either 1 or 0
    		c=myfile.get();
    		c2=c;
    		 //change color of pixel depending on c
                                     // thse are the if statements that arent been checked
    		 if(c2==49)
    		 {
    			 pix.val[0]==255;
    			  pix.val[1]==0;
    			  pix.val[2]==0;
    			
    		 }
    		 
    		 if(c2==48)
    		 {
    			 pix.val[0]==0;
    			 pix.val[1]==255;
    			 pix.val[2]==0;
    			 
    		 }
    		 //set pixel
    		
    		cvSet2D(img,b1,c1,pix);
    		w++;
    		cout<<w<<"\n";
    		 }
    
    		 }//close 1st for loop
    			myfile.close();
    			cout<<"\n closed";
    			cvShowImage("go",img);
    			cvWaitKey(0);
    			cvReleaseImage(&img );
    			system("pause");
    	 }
    	}
    	return 0;
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > pix.val[0]==255;
    Do you get a "statement has no effect" warning?

    Try bumping up the warning level in the compiler.

    You want =, not ==
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 08-16-2010, 10:00 AM
  2. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  3. How to build a C project?
    By jumpjack in forum C Programming
    Replies: 5
    Last Post: 01-26-2006, 07:35 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM