Skip to content

Commit

Permalink
added code for iplimage and removed seg faults
Browse files Browse the repository at this point in the history
  • Loading branch information
p-kar committed Nov 21, 2013
1 parent 3b3380b commit 361deca
Show file tree
Hide file tree
Showing 315 changed files with 2,545 additions and 43 deletions.
Binary file added histograms/histogram_iplimage
Binary file not shown.
37 changes: 23 additions & 14 deletions histograms/histogram_iplimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ int main()
// Mat img_bgr (Size(752,480),CV_8UC3);
IplImage* img_hsv = cvCreateImage(cvSize(752,480),8,3); //Image in HSV color space
IplImage* threshy = cvCreateImage(cvSize(752,480),8,1); //Threshed Image
IplImage* labelImg = cvCreateImage(cvSize(752,480),8,1); //Image Variable for blobs
// IplImage* labelImg = cvCreateImage(cvSize(752,480),8,1); //Image Variable for blobs
IplImage* histogram= cvCreateImage(cvSize(752,480),8,3); //Image histograms
// IplImage* histograms = cvCreateImage(cvSize(752,480),8,1); //greyscale image for histogram
IplImage* empty = cvCreateImage(cvSize(752,1),8,1);
Expand All @@ -142,6 +142,7 @@ int main()

while(1)
{
// printf("1\n");
getFrame(hCam,frame);
// cam.RetrieveBuffer(&rawImage);
// memcpy(frame.data, rawImage.GetData(), rawImage.GetDataSize());
Expand Down Expand Up @@ -179,16 +180,18 @@ int main()

for(int x=0;x<752;++x)
{
// IplImage* col = cvGetCol(threshy,col,x);
IplImage* copy = cvCreateImage(cvSize(752,480),8,1);
cvCopy(copy,threshy);
// cvSetImageROI(copy,cvRect(x,0,x+1,480));
// printf("%d\n", x);
// printf("2\n");
cvSetImageROI(threshy,cvRect(x,0,1,480));
IplImage* copy = cvCreateImage(cvGetSize(threshy),8,1);
cvCopy(threshy,copy,NULL);
cvResetImageROI(threshy);
int y = cvCountNonZero(copy);
if(max<y)
if(max<=y)
max=y;
// for(int j=0 ;j<img.rows;++j)
// img.at<uchar>(0,x) = y;
returnPixel1C(img,0,x) = y;
returnPixel1C(img,x,0) = y;
CvPoint next = cvPoint(x,480-y);
// cvLine(histogram,prev,next,cColor);
// // cvCircle(histogram,next,2,cColor,3);
Expand All @@ -204,27 +207,32 @@ int main()

for(int i=0;i<752;++i)
{
int color = returnPixel1C(img,0,i);
// printf("3\n");
int color = returnPixel1C(img,i,0);
CvPoint next = cvPoint(i,480-color);
cvLine(histogram,prev,next,cColor);
prev = next;
}
// printf("%n\n", &threshold);
for(int i=0;i<752;++i)
{
// printf("4\n");
int counter=0;
if(returnPixel1C(img,0,i)>threshold)
if(returnPixel1C(img,i,0)>threshold)
{
int peak = 0;
int color = 0;
while(1)
{
if(returnPixel1C(img,0,i)<threshold)
// printf("5\n");
if(i>=752)
break;
if(returnPixel1C(img,0,i)>color)
if(returnPixel1C(img,i,0)<threshold)
break;
if(returnPixel1C(img,i,0)>color)
{
peak = i;
color = returnPixel1C(img,0,i);
color = returnPixel1C(img,i,0);
}
++i;
}
Expand All @@ -244,13 +252,14 @@ int main()

if(c == 27)
break;
// printf("6\n");
}

exitCam(hCam);
// Cleanup
cvReleaseImage(&frame);
cvReleaseImage(&threshy);
cvReleaseImage(&img_hsv);
cvReleaseImage(&labelImg);
// cvReleaseImage(&labelImg);
cvReleaseImage(&histogram);
cvDestroyAllWindows();
return 0;
Expand Down
Binary file modified histograms/histogram_ueye
Binary file not shown.
67 changes: 39 additions & 28 deletions histograms/histogram_ueye.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using namespace cv;
char* imgPointer = NULL;
int imgMemPointer;

// enum CamError {CAM_SUCCESS = 1, CAM_FAILURE = 0};
enum CamError {CAM_SUCCESS = 1, CAM_FAILURE = 0};

CvScalar cColor = CV_RGB(255, 255, 255);
CvScalar cColor1 = CV_RGB(255,0,0);
Expand Down Expand Up @@ -67,21 +67,21 @@ int setImgMem(HIDS hCam)
{
is_GetError (hCam, &err, &errMsg);
printf("MemAlloc Unsuccessful %d: %s\n",err,errMsg);
return EXIT_FAILURE;
return CAM_FAILURE;
}

nRet = is_SetImageMem (hCam, imgPointer, imgMemPointer);
if(nRet != IS_SUCCESS)
{
is_GetError (hCam, &err, &errMsg);
printf("Could not set/activate image memory %d: %s\n",err, errMsg);
return EXIT_FAILURE;
return CAM_FAILURE;
}

return EXIT_SUCCESS;
}

void getFrame(HIDS hCam, Mat frame)
bool getFrame(HIDS hCam, Mat frame)
{
char* errMsg = (char*)malloc(sizeof(char)*200);
int err = 0;
Expand All @@ -92,12 +92,15 @@ void getFrame(HIDS hCam, Mat frame)
{
is_GetError (hCam, &err, &errMsg);
printf("Could not grab image %d: %s\n",err,errMsg);
//return EXIT_FAILURE;
return CAM_FAILURE;
}

else
{
memcpy(frame.data, imgPointer, 752*480 * 3);
return CAM_SUCCESS;
}
//fill in the OpenCV imaga data
//IplImage* img_rgb = cvCreateImage(cvSize(752,480),8,3);
memcpy(frame.data, imgPointer, 752*480 * 3);
//IplImage* img_rgb = cvCreateImage(cvSize(752,480),8,3)
//img_rgb->imageData = imgPointer;
//return img_rgb;
}
Expand All @@ -117,26 +120,25 @@ int main()
//INITIALIZE CAMERA
HIDS hCam = 1;
initializeCam(hCam);
setImgMem(hCam);

//Image Variables
Mat frame (Size(752,480),CV_8UC3);
Mat img_bgr (Size(752,480),CV_8UC3);
Mat img_hsv (Size(752,480),CV_8UC3); //Image in HSV color space
Mat threshy (Size(752,480),CV_8UC1); //Threshed Image
// Mat labelImg (Size(752,480),CV_8UC1); //Image Variable for blobs
IplImage* histogram= cvCreateImage(cvSize(752,480),8,3); //Image histograms
Mat histograms (Size(752,480),CV_8UC1); //greyscale image for histogram
Mat empty (Size(752,1),CV_8UC1);
Mat img (Size(752,1),CV_8UC1); //image colours (histogram)


setImgMem(hCam);
//Image Variables
Mat frame = Mat(Size(752,480),CV_8UC3);
// Mat img_bgr (Size(752,480),CV_8UC3);
Mat img_hsv = Mat(Size(752,480),CV_8UC3); //Image in HSV color space
Mat threshy = Mat(Size(752,480),CV_8UC1); //Threshed Image
// Mat labelImg (Size(752,480),CV_8UC1); //Image Variable for blobs
IplImage* histogram= cvCreateImage(cvSize(752,480),8,3); //Image histograms
// Mat histograms (Size(752,480),CV_8UC1); //greyscale image for histogram
Mat empty = Mat(Size(752,1),CV_8UC1);
Mat img = Mat(Size(752,1),CV_8UC1); //image colours (histogram)

// CvBlobs blobs;

while(1)
{
getFrame(hCam,frame);

if(getFrame(hCam,frame) == CAM_FAILURE)
continue;
// cam.RetrieveBuffer(&rawImage);
// memcpy(frame.data, rawImage.GetData(), rawImage.GetDataSize());
// histogram = empty.clone();
Expand Down Expand Up @@ -192,15 +194,18 @@ int main()
cvLine(histogram,prev,next,cColor);
prev = next;
}
// printf("%n\n", &threshold);
// printf("%n\n",histograms &threshold);
int counter = 0;
for(int i=0;i<752;++i)
{
if(img.at<uchar>(0,i)>threshold)
{
int peak = 0;
int color = 0;
while(1)
{
{
if(i>=752)
break;
if(img.at<uchar>(0,i)<threshold)
break;
if(img.at<uchar>(0,i)>color)
Expand All @@ -211,6 +216,11 @@ int main()
++i;
}
line(frame,cvPoint(peak,0),cvPoint(peak,480),cColor1);
++counter;
if(counter == 1)
putText(frame, "GP1", cvPoint(peak,240), FONT_HERSHEY_SIMPLEX, 0.3, cvScalar(255,255,0), 1, CV_AA);
if(counter == 2)
putText(frame, "GP2", cvPoint(peak,240), FONT_HERSHEY_SIMPLEX, 0.3, cvScalar(255,255,0), 1, CV_AA);
}
}

Expand All @@ -224,14 +234,15 @@ int main()

if(c == 27)
break;
}

//Cleanup
}
exitCam(hCam);
// Cleanup
// cvReleaseImage(&frame);
// cvReleaseImage(&threshy);
// cvReleaseImage(&img_hsv);
// cvReleaseImage(&labelImg);
// cvReleaseImage(&histogram);
cvDestroyAllWindows();
// cvDestroyAllWindows();
return 0;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
607 27.832 65.375 1.5385 120
613 29.59 69.066 1.4286 107
616 30.469 74.977 1.3333 100
620 31.641 77.928 1.25 92
624 32.812 81.619 1.2121 86
625 33.105 95.372 1.0811 77
626 33.398 95.442 1.0526 75
629 34.277 103.11 1 69
630 34.57 107.65 0.97561 66
636 36.328 107.27 0.90909 58
638 36.914 116.57 0.86957 52
639 37.207 121.77 0.83333 48
640 37.5 128.1 0.8 44
645 38.965 129.47 0.74074 40
647 39.551 133.69 0.71429 37
648 39.844 139.93 0.68966 33
653 41.309 149.77 0.625 25
654 41.602 163.43 0.60606 19
658 42.773 182.93 0.54795 9
667 45.41 192.42 0.47619 1
668 45.703 194.66 0.47059 -0
670 46.289 212.79 0.44944 -8
673 47.168 214.73 0.41667 -8
675 47.754 223.39 0.4 -12
680 49.219 248.98 0.36364 -22
684 50.391 265.67 0.33333 -28
686 50.977 270.46 0.32 -29
689 51.855 283.56 0.29851 -33
693 53.027 316.26 0.27778 -45
695 53.613 342.57 0.25974 -51
698 54.492 357.03 0.2454 -54
700 55.078 380.19 0.23529 -62
700 55.078 380.19 0.23529 -62
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
607 27.832 65.375 1.5385 120
608 28.125 65.991 1.5201 117.83
609 28.418 66.606 1.5018 115.67
610 28.711 67.221 1.4835 113.5
611 29.004 67.836 1.4652 111.33
612 29.297 68.451 1.4469 109.17
613 29.59 69.066 1.4286 107
614 29.883 71.037 1.3968 104.67
615 30.176 73.007 1.3651 102.33
616 30.469 74.977 1.3333 100
617 30.762 75.715 1.3125 98
618 31.055 76.453 1.2917 96
619 31.348 77.19 1.2708 94
620 31.641 77.928 1.25 92
621 31.934 78.851 1.2405 90.5
622 32.227 79.773 1.2311 89
623 32.52 80.696 1.2216 87.5
624 32.812 81.619 1.2121 86
625 33.105 95.372 1.0811 77
626 33.398 95.442 1.0526 75
627 33.691 97.999 1.0351 73
628 33.984 100.56 1.0175 71
629 34.277 103.11 1 69
630 34.57 107.65 0.97561 66
631 34.863 107.59 0.96452 64.667
632 35.156 107.53 0.95344 63.333
633 35.449 107.46 0.94235 62
634 35.742 107.4 0.93126 60.667
635 36.035 107.34 0.92018 59.333
636 36.328 107.27 0.90909 58
637 36.621 111.92 0.88933 55
638 36.914 116.57 0.86957 52
639 37.207 121.77 0.83333 48
640 37.5 128.1 0.8 44
641 37.793 128.37 0.78815 43.2
642 38.086 128.65 0.7763 42.4
643 38.379 128.92 0.76444 41.6
644 38.672 129.19 0.75259 40.8
645 38.965 129.47 0.74074 40
646 39.258 131.58 0.72751 38.5
647 39.551 133.69 0.71429 37
648 39.844 139.93 0.68966 33
649 40.137 141.9 0.67672 31.4
650 40.43 143.87 0.66379 29.8
651 40.723 145.83 0.65086 28.2
652 41.016 147.8 0.63793 26.6
653 41.309 149.77 0.625 25
654 41.602 163.43 0.60606 19
655 41.895 168.3 0.59153 16.5
656 42.188 173.18 0.577 14
657 42.48 178.05 0.56247 11.5
658 42.773 182.93 0.54795 9
659 43.066 183.98 0.53997 8.1111
660 43.359 185.04 0.532 7.2222
661 43.652 186.09 0.52403 6.3333
662 43.945 187.15 0.51605 5.4444
663 44.238 188.2 0.50808 4.5556
664 44.531 189.26 0.50011 3.6667
665 44.824 190.31 0.49214 2.7778
666 45.117 191.37 0.48416 1.8889
667 45.41 192.42 0.47619 1
668 45.703 194.66 0.47059 -0
669 45.996 203.73 0.46001 -4
670 46.289 212.79 0.44944 -8
671 46.582 213.44 0.43851 -8
672 46.875 214.08 0.42759 -8
673 47.168 214.73 0.41667 -8
674 47.461 219.06 0.40833 -10
675 47.754 223.39 0.4 -12
676 48.047 228.51 0.39273 -14
677 48.34 233.62 0.38545 -16
678 48.633 238.74 0.37818 -18
679 48.926 243.86 0.37091 -20
680 49.219 248.98 0.36364 -22
681 49.512 253.15 0.35606 -23.5
682 49.805 257.33 0.34848 -25
683 50.098 261.5 0.34091 -26.5
684 50.391 265.67 0.33333 -28
685 50.684 268.07 0.32667 -28.5
686 50.977 270.46 0.32 -29
687 51.27 274.83 0.31284 -30.333
688 51.562 279.19 0.30567 -31.667
689 51.855 283.56 0.29851 -33
690 52.148 291.73 0.29333 -36
691 52.441 299.91 0.28814 -39
692 52.734 308.08 0.28296 -42
693 53.027 316.26 0.27778 -45
694 53.32 329.42 0.26876 -48
695 53.613 342.57 0.25974 -51
696 53.906 347.39 0.25496 -52
697 54.199 352.21 0.25018 -53
698 54.492 357.03 0.2454 -54
699 54.785 368.61 0.24035 -58
700 55.078 380.19 0.23529 -62
700 55.078 380.19 0.23529 -62
Binary file not shown.
Loading

0 comments on commit 361deca

Please sign in to comment.