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

this folder consists of files relating to oops_assignment (except helloR... #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
33 changes: 33 additions & 0 deletions arna/oops_assign/beginner_tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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(hello src/helloROS.cpp)
rosbuild_add_executable(game src/play.cpp)
#rosbuild_add_executable(image src/image_proc101.cpp)
1 change: 1 addition & 0 deletions arna/oops_assign/beginner_tutorials/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include $(shell rospack find mk)/cmake.mk
Binary file added arna/oops_assign/beginner_tutorials/bin/game
Binary file not shown.
Binary file added arna/oops_assign/beginner_tutorials/bin/hello
Binary file not shown.
Binary file added arna/oops_assign/beginner_tutorials/bin/image
Binary file not shown.
14 changes: 14 additions & 0 deletions arna/oops_assign/beginner_tutorials/mainpage.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
\mainpage
\htmlinclude manifest.html

\b beginner_tutorials

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

-->


*/
18 changes: 18 additions & 0 deletions arna/oops_assign/beginner_tutorials/manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<package>
<description brief="beginner_tutorials">

beginner_tutorials

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

</package>


9 changes: 9 additions & 0 deletions arna/oops_assign/beginner_tutorials/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

all: image run

image: image_proc101.cpp
g++ -g $^ -o $@ -Wall `pkg-config opencv --cflags --libs`
run:
./image
clean:
rm image
Binary file added arna/oops_assign/beginner_tutorials/src/a.out
Binary file not shown.
16 changes: 16 additions & 0 deletions arna/oops_assign/beginner_tutorials/src/event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<iostream>
#include<cstdio>
#include "point.h"
#include "image_proc101.cpp"

using namespace std;

class evt: public pt{
public:int score,dice,can_play;
evt(int a,int b): pt(a,b){
score=0;can_play=0;
};

void score_update(image* img);
int detect_circle(image* img);
};
14 changes: 14 additions & 0 deletions arna/oops_assign/beginner_tutorials/src/game.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <cstdlib>
#include "event.h"
using namespace std;

class game: public pt{
public:
int winner_score,winner_id;
game(int a,int b): pt(a, b){
x=a;y=b;
winner_score=0;winner_id=0;
};
};

7 changes: 7 additions & 0 deletions arna/oops_assign/beginner_tutorials/src/helloROS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include<iostream>
using namespace std;

int main(){
cout<<"Hello"<<endl;
return 0;
}
Binary file added arna/oops_assign/beginner_tutorials/src/image
Binary file not shown.
28 changes: 28 additions & 0 deletions arna/oops_assign/beginner_tutorials/src/image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
using namespace std;

class image{
public:
cv::Mat img;
int** A,mark,*count_x,*count_y;
image(int a){
img=cv::imread("/home/arnatubai/Desktop/circles2.png",CV_LOAD_IMAGE_COLOR);
A=new int*[img.rows];
for(int i=0;i<img.rows;i++)A[i]=new int[img.cols];
for(int i=0;i<img.rows;i++){
for(int j=0;j<img.cols;j++){
A[i][j]=-1;
}}

mark=0;
cout<<A[10][10]<<endl;
}
cv::Mat game_binary(cv::Mat img);
//int** allocate_A();
cv::Mat qblobdetect(cv::Mat& bin);
void centroid(cv::Mat qblob,int* count_pix);
void process_image();
};
174 changes: 174 additions & 0 deletions arna/oops_assign/beginner_tutorials/src/image_proc101.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include "image.h"

struct ind{int x;int y;
struct ind* next;};
struct ind *front,*rear;


void enqueue(int x,int y){
struct ind* n;
n=(struct ind*)malloc(sizeof(struct ind));
n->x=x;
n->y=y;
n->next=NULL;
if(front==NULL){front=n;rear=front;}
else {rear->next=n;rear=n;}
}
void dequeue(){
struct ind* t;
t=front;
front=t->next;
free(t);
}
void qfront(int* x,int *y){
if(front!=NULL){
*x=front->x;
*y=front->y;}
return;
}
int qempty(){
if(front==NULL)return 1;
return 0;}




cv::Mat image:: game_binary(cv::Mat img){
cv::Mat bin(img.rows,img.cols,CV_8UC1,cvScalarAll(0));
// TODO : img.at<cv::Vec3b>(i, j)[0] = sdfsa
int i,j;
for(i=0;i<img.rows;i++){
for(j=0;j<img.cols;j++){
if( img.at<cv::Vec3b>(i, j)[0]>=235 || img.at<cv::Vec3b>(i, j)[1] >= 235|| img.at<cv::Vec3b>(i, j)[2] >= 235)
bin.at<uchar>(i, j) = 255;
else bin.at<uchar>(i, j) = 0;
}

}
return bin;
}


//int* image:: allocate_centroid(int* )

cv::Mat image:: qblobdetect(cv::Mat& bin){
//std::cout<<"hello";
int i,j,x,y,wd=bin.cols,ht=bin.rows,max_pix_count=0,max_size_index=0;
//cout<<" a->"<<A[10][10]<<" "<<mark<<endl;
for(i=0;i<ht;i++){
for(j=0;j<wd;j++){
if(bin.at<uchar>(i,j)==255){
if(A[i][j]==-1){
mark=mark+1;
enqueue(i,j);

//A[i][j]=0;
while(qempty()==0){
qfront(&x,&y);
int k,l;
dequeue();
for(k=x-1;k<=x+1;k++){
for(l=y-1;l<=y+1;l++){
if((k<ht)&&(l<wd)&&(k>=0)&&(l>=0)&&(A[k][l]==-1) && bin.at<uchar>(k,l)==255){
enqueue(k,l);
A[k][l]=mark;}
}}
A[x][y]=mark;
}
//std::cout<<*mark<<" "<<x<<","<<y<<std::endl;
}
}
}}
//cout<<"A->"<<A[10][10]<<endl;

cv::Mat qblob(bin.rows,bin.cols,CV_8UC3);
//IplImage* qblobdetect=cvCreateImage(cvGetSize(bin),IPL_DEPTH_8U,3);
//int *a;double *c_x,*c_y;

//a=(int*)malloc((*mark+1)*sizeof(int));
for(i=0;i<ht;i++){
for(j=0;j<wd;j++){
if(A[i][j]==-1)qblob.at<cv::Vec3b>(i,j)[0]=qblob.at<cv::Vec3b>(i,j)[1]=qblob.at<cv::Vec3b>(i,j)[2]=255;
else{
qblob.at<cv::Vec3b>(i,j)[0]=255*sin(A[i][j]);
qblob.at<cv::Vec3b>(i,j)[1]=255*cos(A[i][j]);
qblob.at<cv::Vec3b>(i,j)[2]=255*(sin(A[i][j])+cos(A[i][j]))/1.5;
}
}}

//centroid(bin,A,*mark,count_x,count_y);
return qblob;
}

void image:: centroid(cv::Mat qblob,int* count_pix){

for(int i=0;i<=mark;i++)count_pix[i]=0;
for(int i=0;i<=mark;i++)count_x[i]=0;
for(int i=0;i<=mark;i++)count_y[i]=0;
for(int i=0;i<qblob.rows;i++){
for(int j=0;j<qblob.cols;j++){
if(A[i][j]!=-1){
int r=A[i][j];
count_x[r]+=i;
count_y[r]+=j;
count_pix[r]++;
}
}
}
for(int i=1;i<=mark;i++){
count_x[i]/=count_pix[i];
count_y[i]/=count_pix[i];
}
}




void image:: process_image(){

cv::namedWindow("C",CV_WINDOW_AUTOSIZE);
cv::imshow("C",img);
cv::waitKey(0);
cv::Mat gray;
cvtColor(img,gray,CV_BGR2GRAY);
cv::imshow("C",gray);
cv::waitKey(0);
cv::Mat bin=game_binary(img);
cv::imshow("C",bin);
cv::waitKey(0);
std::cout<<bin.rows<<","<<bin.cols<<std::endl;
//std::cout<<"haha";
cv::waitKey(0);
//int** A,mark=0;
//A=allocate_A();
cv::Mat qblob=qblobdetect(bin);

std::cout<<mark<<std::endl;
cv::imshow("C",qblob);
cv::waitKey(0);
count_x=new int[mark+1];
count_y=new int[mark+1];
int *count_pix=new int[mark+1];
centroid(qblob,count_pix);
for(int i=1;i<=mark;i++){
std::cout<<i<<":"<<count_x[i]<<","<<count_y[i]<<std::endl;
}
cv::waitKey(0);
cv::destroyWindow("C");
}

/*int main(){
image* real=new image(10);
std::cout<<"hello "<<real->img.rows<<","<<real->img.cols<<endl;
cv::waitKey(0);
real->process_image();
for(int i=1;i<=real->mark;i++){
std::cout<<i<<":"<<real->count_x[i]<<","<<real->count_y[i]<<std::endl;
}
cv::waitKey(0);

}*/
Loading