-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathRectanglesSingleImage.cpp
More file actions
82 lines (67 loc) · 1.78 KB
/
RectanglesSingleImage.cpp
File metadata and controls
82 lines (67 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include "OpenCVUtils.hpp"
#include "RectanglesSingleImage.hpp"
#ifndef __XCODE__
#include <cv.h>
#include <highgui.h>
#endif
using std::string;
using std::vector;
using std::ifstream;
using std::stringstream;
RectanglesSingleImage::RectanglesSingleImage(string fName) : RegionsSingleImage(fName)
{
}
RectanglesSingleImage::RectanglesSingleImage(IplImage *I) : RegionsSingleImage(I)
{
}
RectanglesSingleImage::~RectanglesSingleImage()
{
}
void RectanglesSingleImage::read(string rectFile)
{
ifstream fin(rectFile.c_str());
if(fin.is_open()){
double x,y,w,h, sc;
while(fin >> x >> y >> w >> h >> sc){
vector<double> *r = new vector<double>(5);
double myarray [] = {x,y,w,h,sc};
r->insert (r->begin(), myarray, myarray+5);
RectangleR *rect = new RectangleR(NULL, r);
delete(r);
list->push_back( (Region *)rect );
}
}else{
std::cerr << "Could not open file " << rectFile << std::endl;
assert(false);
}
fin.close();
}
void RectanglesSingleImage::read(ifstream &fin, int n)
{
for(int i=0; i<n; i++){
double x,y,w,h, sc;
string line;
getline(fin, line);
stringstream ss(line);
ss >> x >> y >> w >> h >> sc;
vector<double> *r = new vector<double>(5);
double myarray [] = {x,y,w,h, sc};
r->insert (r->begin(), myarray, myarray+5);
RectangleR *rect = new RectangleR(NULL, r);
delete(r);
list->push_back( (Region *)rect );
}
}
void RectanglesSingleImage::show(){
IplImage *mask = cvCreateImage(cvGetSize(im), im->depth, im->nChannels);
cvCopy(im, mask, 0);
for(unsigned int i=0; i<list->size(); i++){
((RectangleR *)(list->at(i)))->display(mask, CV_RGB(255,0,0), 3, NULL);
}
showImage("Rectangles", mask);
cvReleaseImage(&mask);
}