How to create .exe project of dot net (C#) of MS Access Data Base.

If you want to create .exe Setup Project of your **Dot Net** Application which is using **MS Access DATA BASES**. then simply follow this steps. Please read this one for a moment before to proceed these steps.[Connect with MS Access Data Base in Dot net][1].
When you are going to create the exe file then your data base connection string should be like this(means there should be no directory in @”Data source, Just direct put the name of your data base, because in .exe file when you add your data base file, then it is in the same directory.

System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
      conn.ConnectionString = @”Provider=Microsoft.ACE.OLEDB.12.0;” +
      @”Data source=MyDataBase.accdb”;

1. Right click on your solution file. *(like in Solution Explorer “Solution ‘MyProject’ “)*
2. Select Add –>New Project –>Other Project Types
3. Select “Setup”
4. A New project will be added named setup (*with a new tab added to
editor as File System )*
5. Now right click on application folder –>select add –>select folder
new folder will be added under application folder * Now Right click
on newly added folder –>select add –>select file * Add File dialog
will be popup
6. Select your Db file *(means from a “Browse” Button there go and select your Access Data Base )*
7. Select Setup project and build.. Now your
installer will have your DB.

Some screen shot which will help you

Step 1 picture:
Image

Step2 Picture:

 

 

Image

Detection of Face in Open CV, simple method

As i also have uploaded the “detection of face and eye”  tutorial but now at this time, i am only discussing the “Detection of Face”. The code given below is well commented. So just copy it your project, and it will work 100%.

/*
This program will detect the face of each person from the picture. For this you also have to upload the “haarcascade xml file”
because in this xml file all the data is available about different faces, so you will got a rectangel drawn at accurate face
DATED: 22/01/2013 (N.W.F.P UET MARDAN CAMPUS) 7TH SEMESTER
*/
#include<cv.h>
#include<highgui.h>
using namespace cv;
using namespace std;

int main()
{
CascadeClassifier cascade;

// this will upload the “haarcascade xml file”…
if (!cascade.load(“C:\\opencv/data/haarcascades/haarcascade_frontalface_alt.xml”))
printf(“XML file loading is missing !\nSo, you will not be able to detect the faces in the pic”);

//uploading the pic
Mat src = imread(“C:\\images/batch8.jpg”,1);
if (src.empty())
printf(“Image is not upload successfully!”);

Mat gray;
cvtColor(src, gray, CV_BGR2GRAY);
equalizeHist(gray, gray);

vector<Rect> faces;
cascade.detectMultiScale(gray, faces, 1.2, 3);

for (int i = 0; i < faces.size(); i++)//size will show that how many faces have been detecte, if there is an image with two person size =2
{
//printf(“X & Y position of Rect are: %d,%d\n”,faces[i].x,faces[i].y);
Rect r = faces[i];
rectangle(src, Point(r.x, r.y), Point(r.x + r.width, r.y + r.height), CV_RGB(0,0,255));
printf(“Area of Rect %d is %d\n”,i,(r.width*r.height));
}

imshow(“src”, src);
waitKey(0);
return 0;
}

The Result of this code should be like this:

picd

Detect face and Eye through CAM in Open CV

This tutorial will explain you that how to detect the human face and eyes, when a CAM is open Up and it start video.Here in this tutorial you will get the circle around human face and ellipse around the eye using OPEN CV programming.

#include “opencv2/objdetect/objdetect.hpp”
#include “opencv2/highgui/highgui.hpp”
#include “opencv2/imgproc/imgproc.hpp”

#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

/** Function Headers */
void detectAndDisplay( Mat frame );

/** Global variables */
String face_cascade_name = “C:\\opencv/data/haarcascades/haarcascade_frontalface_alt.xml”;
String eyes_cascade_name = “C:\\opencv/data/haarcascades/haarcascade_eye_tree_eyeglasses.xml”;
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
string window_name = “Capture – Face detection”;
RNG rng(12345);

/** @function main */
int main( int argc, const char** argv )
{
CvCapture* capture;
Mat frame;

//– 1. Load the cascades
if( !face_cascade.load( face_cascade_name ) ){ printf(“–(!)Error loading\n”); return -1; };
if( !eyes_cascade.load( eyes_cascade_name ) ){ printf(“–(!)Error loading\n”); return -1; };

//– 2. Read the video stream
capture = cvCaptureFromCAM( -1 );
if( capture )
{
while( true )
{
frame = cvQueryFrame( capture );
//– 3. Apply the classifier to the frame
if( !frame.empty() )
{ detectAndDisplay( frame ); }
else
{ printf(” –(!) No captured frame — Break!”); break; }

int c = waitKey(10);
if( (char)c == ‘c’ ) { break; }
}
}
return 0;
}

/** @function detectAndDisplay */
void detectAndDisplay( Mat frame )
{
std::vector<Rect> faces;
Mat frame_gray;

cvtColor( frame, frame_gray, CV_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );

//– Detect faces
face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

for( int i = 0; i < faces.size(); i++ )
{
Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 0, 0, 255 ), 4, 8, 0 );

Mat faceROI = frame_gray( faces[i] );
std::vector<Rect> eyes;

//– In each face, detect eyes
eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );

for( int j = 0; j < eyes.size(); j++ )
{
Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
circle( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
}
}
//– Show what you got
imshow( window_name, frame );
}

 

and the result which i got is some thing like this:

picd

How to set Image for different HSV value in Open CV?

I want to show you that how to get different action of  HSV value on your image. Here in this tutorial we will have two windows one window will show the CAM video, means the picture which through web cam we are getting from surrounding and another window is the combination of resultant picture from HSV value.

//This progam will find out the HSV value for the given image

#include <cv.h>
#include <highgui.h>

int lowerH=0;
int lowerS=0;
int lowerV=0;

int upperH=180;
int upperS=256;
int upperV=256;

//This function threshold the HSV image and create a binary image
IplImage* GetThresholdedImage(IplImage* imgHSV){

IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
cvInRangeS(imgHSV, cvScalar(lowerH,lowerS,lowerV), cvScalar(upperH,upperS,upperV), imgThresh);

return imgThresh;

}
//This function create two windows and 6 trackbars for the “Ball” window

void setwindowSettings()
{
cvNamedWindow(“Video”);
cvNamedWindow(“Ball”);

cvCreateTrackbar(“LowerH”, “Ball”, &lowerH, 180, NULL);
cvCreateTrackbar(“UpperH”, “Ball”, &upperH, 180, NULL);

cvCreateTrackbar(“LowerS”, “Ball”, &lowerS, 256, NULL);
cvCreateTrackbar(“UpperS”, “Ball”, &upperS, 256, NULL);

cvCreateTrackbar(“LowerV”, “Ball”, &lowerV, 256, NULL);
cvCreateTrackbar(“UpperV”, “Ball”, &upperV, 256, NULL);
}

int main(){
CvCapture* capture =0;

capture = cvCaptureFromCAM(0);
if(!capture){
printf(“Capture failure\n”);
return -1;
}

IplImage* frame=0;

setwindowSettings();

//iterate through each frames of the video
while(true){

frame = cvQueryFrame(capture);
if(!frame) break;
frame=cvCloneImage(frame);

IplImage* imgHSV = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
cvCvtColor(frame, imgHSV, CV_BGR2HSV); //Change the color format from BGR to HSV

IplImage* imgThresh = GetThresholdedImage(imgHSV);

cvShowImage(“Ball”, imgThresh);
cvShowImage(“Video”, frame);

//Clean up used images
cvReleaseImage(&imgHSV);
cvReleaseImage(&imgThresh);
cvReleaseImage(&frame);

//Wait 80mS
int c = cvWaitKey(80);
//If ‘ESC’ is pressed, break the loop
if((char)c==27 ) break;

}

cvDestroyAllWindows();
cvReleaseCapture(&capture);

return 0;
}

 

pics

Tracking an Object(Blue Colour) in Open CV

If you want to track a blue color Object using open cv, then this tutorial will help you in understanding the step wise method use for identification and recognition a blue color Object.

// TrackColour.cpp : Defines the entry point for the console application.
//

#include “highgui.h”
#include <cv.h>
using namespace cv;

IplImage* GetThresholdedImage(IplImage* img)
{
// Convert the image into an HSV image
IplImage* imgHSV = cvCreateImage(cvGetSize(img), 8, 3);
cvCvtColor(img, imgHSV, CV_BGR2HSV);

IplImage* imgThreshed = cvCreateImage(cvGetSize(img), 8, 1);

// Values 20,100,100 to 30,255,255 working perfect for yellow at around 6pm
cvInRangeS(imgHSV, cvScalar(112, 100, 100), cvScalar(124, 255, 255), imgThreshed);//this will not recognize the yellow color
cvReleaseImage(&imgHSV);

return imgThreshed;
}

int main()
{
// Initialize capturing live feed from the camera
CvCapture* capture = 0;
capture = cvCaptureFromCAM(0);

// Couldn’t get a device? Throw an error and quit
if(!capture)
{
printf(“Could not initialize capturing…\n”);
return -1;
}
cvNamedWindow(“video”);
// the tracked positions of the ball
IplImage* imgScribble = NULL;

// An infinite loop
while(true)
{
// Will hold a frame captured from the camera
IplImage* frame = 0;
frame = cvQueryFrame(capture);
// If we couldn’t grab a frame… quit
if(!frame)
break;

// If this is the first frame, we need to initialize it

imgScribble = cvCreateImage(cvGetSize(frame), 8, 3);//we are resfreshing it agian and again so that the circle draw from previous fram should not be availble with the new one circle

// Holds the yellow thresholded image (yellow = white, rest = black)
IplImage* imgYellowThresh = GetThresholdedImage(frame);

// Calculate the moments to estimate the position of the ball
CvMoments *moments = (CvMoments*)malloc(sizeof(CvMoments));
cvMoments(imgYellowThresh, moments, 1);

// The actual moment values
double moment10 = cvGetSpatialMoment(moments, 1, 0);
double moment01 = cvGetSpatialMoment(moments, 0, 1);
double area = cvGetCentralMoment(moments, 0, 0);

// Holding the last and current ball positions
static int posX = 0;
static int posY = 0;
int lastX = posX;
int lastY = posY;
posX = moment10/area;
posY = moment01/area;
//preparing the color of the circle
CvScalar blue = CV_RGB(0,0,250);
CvPoint pt2 = cvPoint(posX,posY);
cvCircle(imgScribble,pt2,30,blue,2,8);//draw a circle

// Add fram from CAM and the empty image where we are drawing the line
cvAdd(frame, imgScribble, frame);
cvShowImage(“video”, frame);//if we write “imgScribble” here then we will got an empty image screen where line will draw.

// Wait for a keypress
int c = cvWaitKey(10);
if(c==27)//if i press “escape” key
break;
// Release the thresholded image… we need no memory leaks.. please
cvReleaseImage(&imgYellowThresh);

delete moments;
}

// We’re done using the camera. Other applications can now use it
cvReleaseCapture(&capture);
return 0;
}

and the result which i got :

pic

Drawing Rectangle,Circle and Text on the image in OPEN CV

This tutorial will help you in learning, how to draw circle, rectangle, text and line on any image in Open CV.

#include<cv.h>
#include<highgui.h>
using namespace cv;

int main()
{
// Line variables
CvPoint pt1 = cvPoint(250,60);
CvPoint pt2 = cvPoint(405,195);
CvScalar red = CV_RGB(250,0,0);//RGB=250,0,0 thats why we are getting RED
int thickness = 2;
int connectivity = 8;

// Circle variables
int radius = 30;
CvScalar blue = CV_RGB(0,0,250);

// Text variables
const char* text = “testing”;
double hscale = 1.0;
double vscale = 0.8;
double shear = 0.2;
int thickness2 = 1;
int line_type = 8;

IplImage* src1 = cvLoadImage(“C:\\prado.jpg”,1);
CvFont font1;
cvInitFont(&font1,CV_FONT_HERSHEY_DUPLEX,hscale,vscale,shear,thickness,line_type);

cvLine(src1,pt1,pt2,red,thickness,connectivity);
cvCircle(src1,pt2,radius,blue,thickness,connectivity);
cvPutText(src1,text,pt1,&font1,blue);
cvRectangle( src1, cvPoint(270,30), cvPoint(300,150),cvScalar(0,250,0) );
cvShowImage(“Drawing_and_Text”, src1);
cvWaitKey(0);

return 0;
}

How to Capture frame(pictures) from a video or CAM?

Here in this OpenCV tutorial i will show you, that how to get frame from your web came and then show it in your open cv window.

First of all you should understand here, that i am not going to call a web cam and make a video, but here in this tutorial i will capture the picture from a user or any object through CAM and will use this pic in my own created Open CV window, and it will look like a video is going on.Actually it is not a video from a CAM, but it is the combination of all the pictures which i have capture throug my CAM and have put it into my Open CV window.

You can get picture either from CAM or from any video which is placed in your computer. here in this tutorial i’ll get all the frame from a CAM.

int main()
{
CvCapture* capture = 0;
capture = cvCaptureFromCAM(0);
// capture =cvCaptureFromAVI(“C:\\Users/Public/Videos/Sample Videos/wildlife.wmv”);//if we want to use our  video,

if(!capture)
{
printf(“Could not initialize capturing…\n”);
return -1;
}
IplImage* frame = 0;
cvNamedWindow(“video”);

while(true)
{
frame = cvQueryFrame(capture);
if(!frame)
break;
cvShowImage(“video”, frame);

//press ‘escape’ key to terminate the program
int c = cvWaitKey(20);
if((char)c==27 )//27 is ASCII value of ‘escape’ key
return 0;
}

cvReleaseCapture(&capture);
return 0;
}

Convert Some Pixels of an image in Open CV

Here in this example i am selecting 300 pixel from an image dynamically and then over write it through white color pixel.

#include <opencv/cv.h>
#include <opencv/highgui.h>

using namespace std;
using namespace cv;
void salt(Mat &image,int);//Prototype which show that i am using this type of function in future
int main()
{
Mat myImg=imread(“C:\\prado.jpg”,1);
if(myImg.data)
{
printf(“you got an Image successfuly from directory”);

imshow(“real image”,myImg);
salt(myImg,3000);//Calling a Function which will change the pixel value by chosing pixel from an image dynamically
imshow(“Modify_Image”,myImg);//display the modified image
waitKey(0);
}
else
printf(“Your image is not available in your chosen directory”);
return 0;
}
//–Change Some pixel of an Image—\\

void salt(Mat &image, int n)
{
for (int k=0; k<n; k++)
{
// rand() is the MFC random number generator
// try qrand() with Qt
int i= rand()%image.cols;
int j= rand()%image.rows;
if (image.channels() == 1)
{
// gray-level image
image.at<uchar>(j,i)= 255;
}
else if (image.channels() == 3)
{ // color image
image.at<Vec3b>(j,i)[0]= 255;
image.at<Vec3b>(j,i)[1]= 255;
image.at<Vec3b>(j,i)[2]= 255;
}
}
}

How to Load,Modify,display and store images in Open CV

Here in this tutorial i will show you that how to Load an image from your chosen directory and then convert it into gray color, and then store the new one(modified) image in a directory C:\\Images.

The code is given below:

#include <cv.h>
#include <highgui.h>,
using namespace cv;

int main( )

{

Mat img;

img = imread(“C:\\prado.jpg”, 1 );

if( !img.data )
{
printf( ” No image data \n ” );
return -1;
}
else
prinf(“Your program is working well”);
Mat gray_image;

cvtColor( img, gray_image, CV_RGB2GRAY );
imwrite( “C://images/Gray_Image.jpg”, gray_image);
imshow( “real image”, img);
imshow( “Gray image”, gray_image);
waitKey(0);
return 0;
}

EXPLANATION: 

Mat img = imread(“C:\\prado.jpg”, 1 );

this means to get image from my directory and store it in Mat object which is “img” here, actually Mat object store the data of any image.

cvtColor( img, gray_image, CV_RGB2GRAY );

This line convert the originial (RGB) into other color image(GRAY)

imwrite( “C://images/Gray_Image.jpg”, gray_image);

This one store the new modified image which have been store in Mat object “gray_image” in the directory C://images/ you can chose your own directory

 

 

 

HOW TO READ DATA FROM A FILE AND TO SAVE DATA TO THE FILE AND ALSO THO LOAD THE IMAGE PRESENT IN SDCARE

In this Android program i vl create three button one for saving the file and other to load that file and third 1 is for loading the Image present in the sdcard 

FIRS OF ALL CREATE THE Class like “FileReadWriteSdcardProgramActivity” and then create the package like  “com.pir.sdcardreadwriteoperation;”

 now start the .java class like

                                            //—FileReadWriteSdcardProgramActivity.java—//

package com.pir.sdcardreadwriteoperation;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class FileReadWriteSdcardProgramActivity extends Activity {
EditText txtData;
Button btnReadSDFile,imgbtn,btnWriteSDFile;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtData = (EditText) findViewById(R.id.txtData);
//—————————————————–//
txtData.setHint(“Enter some lines of data here…”);
//—————————————————–//
imgbtn = (Button) findViewById(R.id.imgbtn);
btnReadSDFile = (Button) findViewById(R.id.btnReadSDFile);
btnWriteSDFile = (Button) findViewById(R.id.btnWriteSDFile);

//—–WRITING DATA TO THE FILE
btnWriteSDFile.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{

try {

File myFile = new File(“/sdcard/FileInputOutput/mysdfile.txt”);
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =new OutputStreamWriter(fOut);
myOutWriter.append(txtData.getText());
myOutWriter.close();
fOut.close();
Toast.makeText(v.getContext(),”Done writing SD ‘mysdfile.txt'”, Toast.LENGTH_SHORT).show();
txtData.setText(“”);
}
catch (Exception e)
{
Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
}

});

//—READING DATA FROM THE FILE PLACED IN SDCARD
btnReadSDFile.setOnClickListener(new OnClickListener()
{

public void onClick(View v)
{

try {
File myFile = new File(“/sdcard/FileInputOutput/mysdfile.txt”);
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
String aDataRow = “”;
String aBuffer = “”;
while ((aDataRow = myReader.readLine()) != null)
{
aBuffer += aDataRow +”\n”;
}
txtData.setText(aBuffer);
myReader.close();//*/
Toast.makeText(v.getContext(),”Done reading SD ‘mysdfile.txt'”,Toast.LENGTH_SHORT).show();
}

catch (Exception e)
{
Toast.makeText(v.getContext(), e.getMessage(),Toast.LENGTH_SHORT).show();
}
}
});

//–GETING AN IMAGE FROM THE FILE
imgbtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{

String path = Environment.getExternalStorageDirectory()+ “/FileInputOutput/img1.jpg”;
File imgFile = new File(path);
if(imgFile.exists())
{
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
ImageView myImage = (ImageView) findViewById(R.id.imageView1);
myImage.setImageBitmap(myBitmap);
}
else
Toast.makeText(v.getContext(),”no IMAGE IS PRESENT'”,Toast.LENGTH_SHORT).show();
}
});

}//END OF THE “ONCREATE” FUNCTION…
}//END OF THE MAIN ACTIVITY…

//*****************************main.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical” >

<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />

<ImageView
android:id=”@+id/imageView1″
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_weight=”0.01″
android:background=”@drawable/img2″/>

<EditText
android:id=”@+id/txtData”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginTop=”33dp”
android:layout_weight=”0.06″
android:ems=”10″ >

<requestFocus />
</EditText>

<Button
android:id=”@+id/imgbtn”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginBottom=”-53dp”
android:text=”Load image from a file” />

<Button
android:id=”@+id/btnReadSDFile”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_marginTop=”55dp”
android:text=”Show File Data” />

<Button
android:id=”@+id/btnWriteSDFile”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:text=”Save Data” />

</LinearLayout>

                       < ROBO-TECHI >