Ask Your Question

dnarayanan93's profile - activity

2015-02-09 10:11:01 -0600 received badge  Editor (source)
2015-02-09 10:06:46 -0600 asked a question help in shape and color detection in python opencv

Hi i am a beginner.. For the pyrhon code below it does colour and object detection.. how do i add shape detection to it?? i mean i want to detect color and shape of the object and get the centroid.. My aim.. Plz help.. thanks in advance..

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cv2, math
import numpy as np
class ColourTracker:
      def __init__(self):
          cv2.namedWindow("ColourTrackerWindow", cv2.CV_WINDOW_AUTOSIZE)
          self.capture = cv2.VideoCapture(0)
          self.scale_down = 4
      def run(self):
          while True:
              f, orig_img = self.capture.read()
              #orig_img = cv2.flip(orig_img, 1)
              img = cv2.GaussianBlur(orig_img, (5,5), 0)
              #laplacian = cv2.Laplacian(orig_img,cv2.CV_64F)
              sobelx = cv2.Sobel(orig_img,cv2.CV_64F,1,0,ksize=5)
              sobely = cv2.Sobel(orig_img,cv2.CV_64F,0,1,ksize=5)
              img = cv2.cvtColor(orig_img, cv2.COLOR_BGR2HSV)
              img = cv2.resize(img, (len(orig_img[0]) / self.scale_down, len(orig_img) / self.scale_down))
          boundaries = [([0, 150, 150], [5, 255, 255]),
                            ([40, 80, 10], [255, 255, 255]),
                            ([190, 150, 100], [255, 255, 255])]
              for (lower, upper) in boundaries:
                              lower = np.array(lower,np.uint8)
                              upper = np.array(upper,np.uint8)
                              binary = cv2.inRange(img, lower, upper)
                              dilation = np.ones((15, 15), "uint8")
                              binary = cv2.dilate(binary, dilation)
                              #edge = cv2.Canny(red_binary,200,300,apertureSize = 3)
                              contours, hierarchy = cv2.findContours(binary, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
                              max_area = 0
                              largest_contour = None
                              for idx, contour in enumerate(contours):
                                  area = cv2.contourArea(contour)
                                  if area > max_area:
                                      max_area = area
                                      largest_contour = contour
                                      if not largest_contour == None:
                                          moment = cv2.moments(largest_contour)
                                          if moment["m00"] > 1000 / self.scale_down:
                                              rect = cv2.minAreaRect(largest_contour)
                                              rect = ((rect[0][0] * self.scale_down, rect[0][1] * self.scale_down), (rect[1][0] * self.scale_down, rect[1][1] * self.scale_down), rect[2])
                                              box = cv2.cv.BoxPoints(rect)
                                              box = np.int0(box)
                                              cv2.drawContours(orig_img,[box], 0, (0, 0, 255), 2)
                                              cv2.imshow("ColourTrackerWindow", orig_img)
                                              if cv2.waitKey(20) == 27:
                                                  cv2.destroyWindow("ColourTrackerWindow")
                                                  self.capture.release()
                                                  break
if __name__ == "__main__":
   colour_tracker = ColourTracker()
   colour_tracker.run()
2014-05-15 00:58:59 -0600 commented question import error

read the procedure from where you are referring once again carefully! you'll get it write!

2014-05-15 00:54:46 -0600 commented question pan tilt face detection

Nope! I have added the .cpp and .h files into the project directory, if i don't add them i get an error saying that these files are missing! and after adding them i get this mind boggling error!

2014-05-15 00:48:10 -0600 commented question pan tilt face detection

TSerial is not a library, so i'm not able to link it, it's just a .cpp file!

2014-05-15 00:38:47 -0600 asked a question pan tilt face detection

HI THIS IS MY PROGRAM

include "stdafx.h"

include "opencv2/objdetect/objdetect.hpp"

include "opencv2/highgui/highgui.hpp"

include "opencv2/imgproc/imgproc.hpp"

include <iostream>

include "Tserial.h"

using namespace std; using namespace cv;

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

/** Global variables */ //-- Note, either copy these two files from opencv/data/haarscascades to your current folder, or change these locations String face_cascade_name = "haarcascade_frontalface_alt.xml"; String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml"; CascadeClassifier face_cascade; CascadeClassifier eyes_cascade; string window_name = "Capture - Face detection - Remixed by TechBitar";

// Serial to Arduino global declarations int arduino_command; Tserial *arduino_com; short MSBLSB = 0; unsigned char MSB = 0; unsigned char LSB = 0; // Serial to Arduino global declarations

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

// serial to Arduino setup arduino_com = new Tserial(); if (arduino_com!=0) { arduino_com->connect("COM8", 57600, spNONE); } // serial to Arduino setup

//-- 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( 0 ); 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; } 
}

} // Serial to Arduino - shutdown arduino_com->disconnect(); delete arduino_com; arduino_com = 0; // Serial to Arduino - shutdown 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].width0.5, faces[i].y + faces[i].height0.5 ); ellipse( frame, center, Size( faces[i].width0.5, faces[i].height0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 2, 8, 0 ); // cout << "X:" << faces[i].x << " y:" << faces[i].y << endl;

 // send X,Y of face center to serial com port  
 // send X axis
 // read least significant byte 
 LSB = faces[i].x & 0xff;
 // read next significant byte 
 MSB = (faces[i].x >> 8) & 0xff;
 arduino_com->sendChar( MSB );
 arduino_com->sendChar( LSB );

// Send Y axis
LSB = faces[i].y & 0xff;
MSB = (faces[i].y >> 8) & 0xff;
arduino_com->sendChar( MSB );
arduino_com->sendChar( LSB );

// serial com port send

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

//-- Show what you got imshow( window_name, frame );

}

NOW I'M GETTING THESE ERRORS IN VC++ 2010, HOW DO I RESOLVE THIS?

1>facedetect.obj : error LNK2019: unresolved external symbol "public: void __thiscall Tserial::disconnect(void)" (?disconnect@Tserial@@QAEXXZ) referenced in function _main 1>facedetect.obj : error LNK2019: unresolved external symbol "public: int __thiscall Tserial::connect(char *,int,enum serial_parity)" (?connect@Tserial@@QAEHPADHW4serial_parity@@@Z) referenced in function _main 1>facedetect.obj : error LNK2019: unresolved external symbol "public: __thiscall Tserial::Tserial(void)" (??0Tserial@@QAE@XZ) referenced in function _main 1>facedetect.obj : error LNK2019: unresolved external symbol "public: __thiscall Tserial::~Tserial(void)" (??1Tserial@@QAE@XZ) referenced in function "public: void * __thiscall Tserial::`scalar deleting destructor'(unsigned int)" (??_GTserial@@QAEPAXI ... (more)