Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added OOP and ROS assignments. #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Getting a compile error after integrating opencv. Trying to resolve t…
…he error.
abinashmeher999 committed Mar 15, 2014
commit 1aae3e0e8ba697c364ae3f5cf4ff21946b45762e
29 changes: 0 additions & 29 deletions Abinash/OOP_Assignment/Board.cpp

This file was deleted.

31 changes: 31 additions & 0 deletions Abinash/OOP_Assignment/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)

# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
#set(ROS_BUILD_TYPE RelWithDebInfo)

rosbuild_init()

#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

#uncomment if you have defined messages
#rosbuild_genmsg()
#uncomment if you have defined services
#rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})
rosbuild_add_executable(OOPs_PS src/main.cpp src/Board.cpp src/Player.cpp src/Dice.cpp src/Dice6.cpp src/Game.cpp src/Position.cpp src/Image.cpp src/Board.h src/Player.h src/Dice.h src/Dice6.h src/Game.h src/Position.h src/Image.h)
6 changes: 0 additions & 6 deletions Abinash/OOP_Assignment/Image.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions Abinash/OOP_Assignment/Image.h

This file was deleted.

1 change: 1 addition & 0 deletions Abinash/OOP_Assignment/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(shell rospack find mk)/cmake.mk
7 changes: 0 additions & 7 deletions Abinash/OOP_Assignment/Position.cpp

This file was deleted.

Binary file added Abinash/OOP_Assignment/game.rgb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@
#include "Position.h"
#include "Image.h"

typedef struct{
struct pix{
char c;
Position p;
}pix;
};

struct Chan{
Position r[100];int rn;
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions Abinash/OOP_Assignment/include/OOPs_PS/Image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef IMAGE_H
#define IMAGE_H
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <queue>
#include <cstdlib>
#include <string>
#include "Position.h"
#include "Board.h"

class Image
{
public:
Image(cv::Mat,Board*);

protected:
private:
cv::Mat img;
int blob_count;
int **VISITED;
queue<position> track;
};

#endif // IMAGE_H

File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions Abinash/OOP_Assignment/include/Position.h

This file was deleted.

14 changes: 14 additions & 0 deletions Abinash/OOP_Assignment/mainpage.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
\mainpage
\htmlinclude manifest.html

\b OOPs_PS

<!--
Provide an overview of your package.
-->

-->


*/
17 changes: 17 additions & 0 deletions Abinash/OOP_Assignment/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<package>
<description brief="OOPs_PS">

OOPs_PS

</description>
<author>Abinash Meher</author>
<license>BSD</license>
<review status="unreviewed" notes=""/>
<url>http://ros.org/wiki/OOPs_PS</url>
<depend package="std_msgs"/>
<depend package="rospy"/>
<depend package="roscpp"/>

</package>


Binary file removed Abinash/OOP_Assignment/obj/Debug/Board.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/Dice.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/Dice6.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/Game.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/Image.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/Player.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/Position.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/main.o
Binary file not shown.
Binary file removed Abinash/OOP_Assignment/obj/Debug/src/Position.o
Binary file not shown.
20 changes: 20 additions & 0 deletions Abinash/OOP_Assignment/src/Board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "Board.h"
#include <cstdlib>
#include <ctime>

//void Board::mapped(Image img,int *x,int *y,chan *pa)
//{


//}

Board::Board()
{
srand((unsigned int)time(NULL));
Chan *x;
int i,j,k;
x=&A;
x->rn=0;
x->gn=0;
x->bn=0;//Board::mapped(img,&height,&width,&A);
}
28 changes: 28 additions & 0 deletions Abinash/OOP_Assignment/src/Board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef BOARD_H
#define BOARD_H
#include "Position.h"
#include "Image.h"

struct pix{
char c;
Position p;
};

struct Chan{
Position r[100];int rn;
Position g[100];int gn;
Position b[100];int bn;
};

class Board
{
public:
int height,width;
Chan A;
Board();
private:
//void mapped(Image,int*,int*,chan *pa);

};

#endif // BOARD_H
File renamed without changes.
13 changes: 13 additions & 0 deletions Abinash/OOP_Assignment/src/Dice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef DICE_H
#define DICE_H


class Dice
{
public:
virtual int roll()=0;
protected:
private:
};

#endif // DICE_H
File renamed without changes.
15 changes: 15 additions & 0 deletions Abinash/OOP_Assignment/src/Dice6.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef DICE6_H
#define DICE6_H

#include "Dice.h"


class Dice6 : public Dice
{
public:
int roll();
protected:
private:
};

#endif // DICE6_H
File renamed without changes.
28 changes: 28 additions & 0 deletions Abinash/OOP_Assignment/src/Game.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef GAME_H
#define GAME_H
#include "Player.h"
#include "Dice6.h"
#include "Board.h"
#include "Dice.h"


class Game
{
public:
void StartGame();
void get_players ();//takes no of players and makes players with unique ids
Player** winset;
int no_winners;
Game();
Board bd1;
private:

int no_players;

void trialturn();//executes one turn for each player
Player *Set;
Dice6 dice;

};

#endif // GAME_H
139 changes: 139 additions & 0 deletions Abinash/OOP_Assignment/src/Image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include "Image.h"

cv::Mat Image::image_transform_binary(cv::Mat img0)
{
cv::Mat bin(img0.rows,img0.cols,CV_8UC1,cvScalarAll(0));
for (int i=0;i<img0.rows;i++)
{
for (int j=0;j<img0.cols;j++)
{
if (img0.at<cv::Vec3b>(i,j)[0]==255 && img0.at<cv::Vec3b>(i,j)[1]==0 && img0.at<cv::Vec3b>(i,j)[2]==0) bin.at<uchar>(i,j)=255;
if (img0.at<cv::Vec3b>(i,j)[1]==255 && img0.at<cv::Vec3b>(i,j)[0]==0 && img0.at<cv::Vec3b>(i,j)[2]==0) bin.at<uchar>(i,j)=255;
if (img0.at<cv::Vec3b>(i,j)[2]==255 && img0.at<cv::Vec3b>(i,j)[1]==0 && img0.at<cv::Vec3b>(i,j)[0]==0) bin.at<uchar>(i,j)=255;
}
}
return bin;
}

void find_pass_center(cv::Mat bin,Board* bd)
{
Position* Ctmp = new Position[blob_count];
int *Cn = new int[blob_count];
Position tmp;

for (int m=0;m<blob_count;m++)
{
Ctmp[m].x=0;
Ctmp[m].y=0;
Cn[m]=0;
}

for (int i=0;i<bin.rows;i++)
{
for (int j=0;j<bin.cols;j++)
{
int k=VISITED[i]][j];
if (k!=-1)
{
Ctmp[k].x+=j;
Ctmp[k].y+=i;
Cn[k]++;
}
}
}

for (int z=0;z<blob_count;z++)
{
tmp.x=Ctmp[z].x/Cn[z];
tmp.y=Ctmp[z].y/Cn[z];
if (img.at<cv::Vec3b>(tmp.y,tmp.x)[0]==255)
{
bd->A.b[bd->A.bn]=tmp;
(bd->A.bn)++;
}
if (img.at<cv::Vec3b>(tmp.y,tmp.x)[1]==255)
{
bd->A.g[bd->A.gn]=tmp;
(bd->A.gn)++;
}
if (img.at<cv::Vec3b>(tmp.y,tmp.x)[2]==255)
{
bd->A.r[bd->A.rn]=tmp;
(bd->A.rn)++;
}
}
}

void blob_detect(cv::Mat bin,Board *bd)
{
int height=bin.rows, width=bin.cols;
VISITED=new int*[height];

for(int i=0;i<height;i++)
VISITED[i]=new int[width];

for(i=0;i<height;i++)
{
for(int j=0;j<width;j++)
{
A[i][j]=-1;
}
}

for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
if(bin.at<uchar>(i,j)==255)
{
if(VISITED[i][j]==-1)
{
Position tmp;
tmp.y=i;
tmp.x=j;
track.push(tmp);
while(!track.empty())
{
Position v=track.front();
int k,l;
track.pop();
for(k=v.x-1;k<=v.x+1;k++)
{
for(l=v.y-1;l<=v.y+1;l++)
{
if(k<height && l<width && k>=0 && l>=0 && VISITED[k][l]==-1 && bin.at<uchar>(k,l)==255)
{
Position kl;
kl.y=l;
kl.x=k;
track.push(kl);
VISITED[k][l]=blob_count;
}
}
}
A[v.x][v.y]=blob_count;
}
blob_count++;
}
}
}
}

Image::find_pass_center(bin,bd);
}

Image::Image(std::string file,Board *bd)
{
cv::Mat bin;
img=imread(file);
blob_count=0;
bin=Image::image_transform_binary(img);
cv::namedWindow("OImage",CV_WINDOW_AUTOSIZE);
cv::imshow("OImage",img);
cv::waitKey(0);
cv::namedWindow("Image",CV_WINDOW_AUTOSIZE);
cv::imshow("Image",bin);
cv::waitKey(0);
Image::blob_detect(bin,bd);
}

26 changes: 26 additions & 0 deletions Abinash/OOP_Assignment/src/Image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef IMAGE_H
#define IMAGE_H
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <queue>
#include <cstdlib>
#include <string>
#include "Position.h"
#include "Board.h"

class Image
{
public:
Image(std::string ,Board*);

protected:
private:
cv::Mat img;
int blob_count;
int **VISITED;
queue<position> track;
};

#endif // IMAGE_H

File renamed without changes.
20 changes: 20 additions & 0 deletions Abinash/OOP_Assignment/src/Player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef PLAYER_H
#define PLAYER_H
#include "Position.h"
#include "Board.h"
#include <iostream>
#include <cmath>

class Player
{
public:
Position pos;
int score,id;
void Getdice(int,Board*);
Player();
private:
void shift_position(Position*,int,Board*);
void upgrade_score(int*,int);
};

#endif // PLAYER_H
3 changes: 2 additions & 1 deletion Abinash/OOP_Assignment/src/Position.cpp
Original file line number Diff line number Diff line change
@@ -2,5 +2,6 @@

Position::Position()
{
x=0;y=0;
x=0;
y=0;//ctor
}
5 changes: 4 additions & 1 deletion Abinash/OOP_Assignment/src/Position.h
Original file line number Diff line number Diff line change
@@ -5,8 +5,11 @@
class Position
{
public:
int x,y;
int x;
int y;
Position();
protected:
private:
};

#endif // POSITION_H
Binary file added Abinash/OOP_Assignment/src/game.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "Position.h"
#include "Board.h"
#include "Player.h"
@@ -13,13 +17,16 @@ using namespace std;

int main()
{
int b;
srand((unsigned int)time(NULL));
Game bgame;
string file;
cout<<"Give filename"<<endl;
cin>>file;
Image bimg(file,&(bgame.bd1));
bgame.get_players();
bgame.StartGame();
cout<<"Winners :"<<endl;
for (b=0;b<bgame.no_winners;b++)
for (int b=0;b<bgame.no_winners;b++)
{
cout<<"Player_"<<bgame.winset[b]->id<<endl;
}