Revision history [back]

Help! Show coordinates face detection

Hi! i need calculate the distance between two o more faces (the faces are inside rectangle, because i am using facedetection code in python), and if two or more faces are together(rectangles together) then print " faces together". if(distance(face1 and face2)<= "n" pixel) {print "faces together"} #n = your calibrate distance. I do not know how translate this order to python language, somebody can help me? Thanks. this is the code:

#

----------------------------------------------------------------------------

import cv import time import Image

min_size = (20,20)
image_scale = 2
haar_scale = 1.1
min_neighbors = 3
haar_flags = 0

# Allocate the temporary images
grayscale = cv.CreateImage((image.width, image.height), 8, 1)
smallImage = cv.CreateImage(
(
cv.Round(image.width / image_scale),
cv.Round(image.height / image_scale)
), 8 ,1)

# Convert color input image to grayscale
cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY)

# Scale input image for faster processing
cv.Resize(grayscale, smallImage, cv.CV_INTER_LINEAR)

# Equalize the histogram
cv.EqualizeHist(smallImage, smallImage)

# Detect the faces
faces = cv.HaarDetectObjects(
haar_scale, min_neighbors, haar_flags, min_size
)

# If faces are found
if faces:
for ((x, y, w, h), n) in faces:
# the input to cv.HaarDetectObjects was resized, so scale the
# bounding box of each face and convert it to two CvPoints
pt1 = (int(x * image_scale), int(y * image_scale))
pt2 = (int((x + w) * image_scale), int((y + h) * image_scale))
cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 5, 8, 0)

return image


----------

capture = cv.CaptureFromCAM(0)

capture = cv.CaptureFromFile("test.avi")

while (cv.WaitKey(15)==-1): img = cv.QueryFrame(capture) image = DetectFace(img, faceCascade) cv.ShowImage("face detection test", image)

cv.ReleaseCapture(capture)

 2 No.2 Revision berak 29433 ●4 ●75 ●291

Help! Show coordinates face detection

Hi! i need calculate the distance between two o more faces (the faces are inside rectangle, because i am using facedetection code in python), and if two or more faces are together(rectangles together) then print " faces together". if(distance(face1 and face2)<= "n" pixel) {print "faces together"} #n = your calibrate distance. I do not know how translate this order to python language, somebody can help me? Thanks. this is the code:

#!/usr/bin/python #---------------------------------------------------------------------------- # Face Detection Test (OpenCV)

 # (OpenCV) # # thanks to: http://japskua.wordpress.com/2010/08/04/detecting-eyes-with-python-opencv ---------------------------------------------------------------------------- to: # http://japskua.wordpress.com/2010/08/04/detecting-eyes-with-python-opencv #---------------------------------------------------------------------------- import cv import time import Image Image def DetectFace(image, faceCascade): faceCascade): min_size = (20,20) image_scale = 2 haar_scale = 1.1 min_neighbors = 3 haar_flags = 0 # Allocate the temporary images grayscale = cv.CreateImage((image.width, image.height), 8, 1) smallImage = cv.CreateImage( ( cv.Round(image.width / image_scale), cv.Round(image.height / image_scale) ), 8 ,1) # Convert color input image to grayscale cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY) # Scale input image for faster processing cv.Resize(grayscale, smallImage, cv.CV_INTER_LINEAR) # Equalize the histogram cv.EqualizeHist(smallImage, smallImage) # Detect the faces faces = cv.HaarDetectObjects( smallImage, faceCascade, cv.CreateMemStorage(0), haar_scale, min_neighbors, haar_flags, min_size ) # If faces are found if faces: for ((x, y, w, h), n) in faces: # the input to cv.HaarDetectObjects was resized, so scale the # bounding box of each face and convert it to two CvPoints pt1 = (int(x * image_scale), int(y * image_scale)) pt2 = (int((x + w) * image_scale), int((y + h) * image_scale)) cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 5, 8, 0) return image ---------- #---------- # M A I N ---------- N #---------- capture = cv.CaptureFromCAM(0) capture = cv.CaptureFromFile("test.avi") cv.CaptureFromCAM(0) #capture = cv.CaptureFromFile("test.avi") #faceCascade = cv.Load("haarcascades/haarcascade_frontalface_default.xml") #faceCascade = cv.Load("haarcascades/haarcascade_frontalface_alt2.xml") #faceCascade = cv.Load("haarcascades/haarcascade_frontalface_alt.xml") faceCascade = cv.Load("haarcascades/haarcascade_frontalface_default.xml") faceCascade = cv.Load("haarcascades/haarcascade_frontalface_alt2.xml") faceCascade = cv.Load("haarcascades/haarcascade_frontalface_alt.xml") faceCascade = cv.Load("haarcascades/haarcascade_profileface.xml") faceCascade = cv.Load("haarcascades/haarcascade_frontalface_alt_tree.xml") cv.Load("haarcascades/haarcascade_profileface.xml") #faceCascade = cv.Load("haarcascades/haarcascade_frontalface_alt_tree.xml") while (cv.WaitKey(15)==-1): img = cv.QueryFrame(capture) image = DetectFace(img, faceCascade) cv.ShowImage("face detection test", image) cv.ReleaseCapture(capture)
image) cv.ReleaseCapture(capture) 

Help! Show coordinates face detection

Hi! i need calculate the distance between two o more faces (the faces are inside rectangle, because i am using facedetection code in python), and if two or more faces are together(rectangles together) then print " faces together". if(distance(face1 and face2)<= "n" pixel) {print "faces together"} #n = your calibrate distance. I do not know how translate this order to python language, somebody can help me? Thanks. this is the code:

i am using other code with opencv 2.4.9, this code:

www.robologs.net

import numpy as np import cv2

cargamos la plantilla e inicializamos la webcam:

while(True): #leemos un frame y lo guardamos ret, img = cap.read()

#!/usr/bin/python

#----------------------------------------------------------------------------
# Face Detection Test (OpenCV)
#
# thanks to:
# http://japskua.wordpress.com/2010/08/04/detecting-eyes-with-python-opencv
#----------------------------------------------------------------------------

import cv
import time
import Image

min_size = (20,20)
image_scale = 2
haar_scale = 1.1
min_neighbors = 3
haar_flags = 0

# Allocate the temporary images
grayscale = cv.CreateImage((image.width, image.height), 8, 1)
smallImage = cv.CreateImage(
(
cv.Round(image.width / image_scale),
cv.Round(image.height / image_scale)
), 8 ,1)

# Convert color input image to grayscale
cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY)

# Scale input image #convertimos la imagen a blanco y negro
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
#buscamos las coordenadas de los rostros (si los hay) y
#guardamos su posicion

for faster processing
cv.Resize(grayscale, smallImage, cv.CV_INTER_LINEAR)

# Equalize the histogram
cv.EqualizeHist(smallImage, smallImage)

# Detect the faces
faces = cv.HaarDetectObjects(
haar_scale, min_neighbors, haar_flags, min_size
)

# If faces are found
if faces:
for ((x, y, w, h), n) (x,y,w,h) in faces:
# the input to cv.HaarDetectObjects was resized, so scale the
# bounding box of each face and convert it to two CvPoints
pt1 = (int(x * image_scale), int(y * image_scale))
pt2 = (int((x + w) * image_scale), int((y + h) * image_scale))
cv.Rectangle(image, pt1, pt2, cv.RGB(255, 0, 0), 5, 8, 0)

return image

#----------
# M A I N
#----------

capture = cv.CaptureFromCAM(0)
#capture = cv.CaptureFromFile("test.avi")

while (cv.WaitKey(15)==-1):
img = cv.QueryFrame(capture)
cv.ShowImage("face detection test", image)

cv.ReleaseCapture(capture)
cv2.rectangle(img,(x,y),(x+w,y+h),(125,255,0),2)

#Mostramos la imagen
cv2.imshow('img',img)

#con la tecla 'q' salimos del programa
if cv2.waitKey(1) & 0xFF == ord('q'):
break


cap.release() cv2-destroyAllWindows()

Help! Show coordinates face detection

Hi! i need calculate the distance between two o more faces (the faces are inside rectangle, because i am using facedetection code in python), and if two or more faces are together(rectangles together) then print " faces together". if(distance(face1 and face2)<= "n" pixel) {print "faces together"} #n = your calibrate distance. I do not know how translate this order to python language, somebody can help me? Thanks. this is the code:

i am using other code with opencv 2.4.9, this code:

Ejemplo #Ejemplo de deteccion facial con OpenCV y Python

 Por Glare www.robologs.net Python #Por Glare #www.robologs.net import numpy as np import cv2 cargamos cv2 #cargamos la plantilla e inicializamos la webcam: webcam: face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml') cap = cv2.VideoCapture(0) cv2.VideoCapture(0) while(True): #leemos un frame y lo guardamos ret, img = cap.read() cap.read() #convertimos la imagen a blanco y negro gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) #buscamos las coordenadas de los rostros (si los hay) y #guardamos su posicion faces = face_cascade.detectMultiScale(gray, 1.3, 5) #Dibujamos un rectangulo en las coordenadas de cada rostro for (x,y,w,h) in faces: cv2.rectangle(img,(x,y),(x+w,y+h),(125,255,0),2) #Mostramos la imagen cv2.imshow('img',img) #con la tecla 'q' salimos del programa if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2-destroyAllWindows() cap.release() cv2-destroyAllWindows() 





 Copyright OpenCV foundation, 2012-2018. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license. about | faq | help | privacy policy | terms of service Powered by Askbot version 0.10.2 Please note: OpenCV answers requires javascript to work properly, please enable javascript in your browser, here is how //IE fix to hide the red margin var noscript = document.getElementsByTagName('noscript')[0]; noscript.style.padding = '0px'; noscript.style.backgroundColor = 'transparent'; askbot['urls']['mark_read_message'] = '/s/messages/markread/'; askbot['urls']['get_tags_by_wildcard'] = '/s/get-tags-by-wildcard/'; askbot['urls']['get_tag_list'] = '/s/get-tag-list/'; askbot['urls']['follow_user'] = '/followit/follow/user/{{userId}}/'; askbot['urls']['unfollow_user'] = '/followit/unfollow/user/{{userId}}/'; askbot['urls']['user_signin'] = '/account/signin/'; askbot['urls']['getEditor'] = '/s/get-editor/'; askbot['urls']['apiGetQuestions'] = '/s/api/get_questions/'; askbot['urls']['ask'] = '/questions/ask/'; askbot['urls']['questions'] = '/questions/'; askbot['settings']['groupsEnabled'] = false; askbot['settings']['static_url'] = '/m/'; askbot['settings']['minSearchWordLength'] = 4; askbot['settings']['mathjaxEnabled'] = false; askbot['settings']['sharingSuffixText'] = ''; askbot['settings']['errorPlacement'] = 'after-label'; askbot['data']['maxCommentLength'] = 800; askbot['settings']['editorType'] = 'markdown'; askbot['settings']['commentsEditorType'] = 'rich\u002Dtext'; askbot['messages']['askYourQuestion'] = 'Ask Your Question'; askbot['messages']['questionSingular'] = 'question'; askbot['messages']['answerSingular'] = 'answer'; askbot['messages']['acceptOwnAnswer'] = 'accept or unaccept your own answer'; askbot['messages']['followQuestions'] = 'follow questions'; askbot['settings']['allowedUploadFileTypes'] = [ "jpg", "jpeg", "gif", "bmp", "png", "tiff" ]; askbot['data']['haveFlashNotifications'] = true; askbot['data']['activeTab'] = 'questions'; askbot['settings']['csrfCookieName'] = 'csrftoken'; askbot['data']['searchUrl'] = ''; /*<![CDATA[*/ $('.mceStatusbar').remove();//a hack to remove the tinyMCE status bar$(document).ready(function(){ // focus input on the search bar endcomment var activeTab = askbot['data']['activeTab']; if (inArray(activeTab, ['users', 'questions', 'tags', 'badges'])) { var searchInput = $('#keywords'); } else if (activeTab === 'ask') { var searchInput =$('#id_title'); } else { var searchInput = undefined; animateHashes(); } if (searchInput) { searchInput.focus(); putCursorAtEnd(searchInput); } var haveFullTextSearchTab = inArray(activeTab, ['questions', 'badges', 'ask']); var haveUserProfilePage = $('body').hasClass('user-profile-page'); if ((haveUserProfilePage || haveFullTextSearchTab) && searchInput && searchInput.length) { var search = new FullTextSearch(); askbot['controllers'] = askbot['controllers'] || {}; askbot['controllers']['fullTextSearch'] = search; search.setSearchUrl(askbot['data']['searchUrl']); if (activeTab === 'ask') { search.setAskButtonEnabled(false); } search.decorate(searchInput); } else if (activeTab === 'tags') { var search = new TagSearch(); search.decorate(searchInput); } if (askbot['data']['userIsAdminOrMod']) {$('body').addClass('admin'); } if (askbot['settings']['groupsEnabled']) { askbot['urls']['add_group'] = "/s/add-group/"; var group_dropdown = new GroupDropdown(); $('.groups-dropdown').append(group_dropdown.getElement()); } var userRep =$('#userToolsNav .reputation'); if (userRep.length) { var showPermsTrigger = new ShowPermsTrigger(); showPermsTrigger.decorate(userRep); } }); if (askbot['data']['haveFlashNotifications']) { $('#validate_email_alert').click(function(){notify.close(true)}) notify.show(); } var langNav =$('.lang-nav'); if (langNav.length) { var nav = new LangNav(); nav.decorate(langNav); } /*]]>*/ //todo - take this out into .js file $(document).ready(function(){$('div.revision div[id^=rev-header-]').bind('click', function(){ var revId = this.id.substr(11); toggleRev(revId); }); lanai.highlightSyntax(); }); function toggleRev(id) { var arrow = $("#rev-arrow-" + id); var visible = arrow.attr("src").indexOf("hide") > -1; if (visible) { var image_path = '/m/default/media/images/expander-arrow-show.gif?v=6'; } else { var image_path = '/m/default/media/images/expander-arrow-hide.gif?v=6'; } image_path = image_path + "?v=6"; arrow.attr("src", image_path);$("#rev-body-" + id).slideToggle("fast"); } for (url_name in askbot['urls']){ askbot['urls'][url_name] = cleanUrl(askbot['urls'][url_name]); }