1

I wanna draw rectangle on a detected car.But when I run my code.Nothing shows up. And the screen is lagging.

import cv2
cascade_src = 'cars.xml'
img = cv2.imread('1.png')

##print(img)

car_cascade = cv2.CascadeClassifier(cascade_src)
cars = car_cascade.detectMultiScale(img, 1.1, 1)
##print cars
for (x,y,w,h) in cars:
    cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
    cv2.imshow('image', img)
Muhammet PARLAK
  • 81
  • 2
  • 2
  • 9
  • `img` is just an image - `import Image; img = Image.open("a-picture-of-a-car.jpg")` would replace the `cap.read()`, for instance. – Ken Y-N Jul 12 '17 at 07:14
  • 1
    Possible duplicate of [How do I read an image file using Python?](https://stackoverflow.com/questions/3735553/how-do-i-read-an-image-file-using-python) – Ken Y-N Jul 12 '17 at 07:14
  • I wonder what guys like you would do if there wasn't a spoon-feeding community like this... – Piglet Jul 12 '17 at 07:28
  • @Piglet Isnt this comminucation's purpose asking questions and get illuminated? – Muhammet PARLAK Jul 12 '17 at 07:49
  • yes indeed. but befor you should at least try to find a solution yourself. there are thousands of examples on how to load images in OpenCV, not to mention the OpenCV documentation and tutorials. All could be found by a simple websearch. Also "here's my code, I tried to change it but it doesn't work" is not exactly a very good problem description. you should have at least provided your not working code. else you just appear to be some lazy guy who found some working code online and now is looking for some fool to change it for free. It all boils down to how present your problem. [ask] – Piglet Jul 12 '17 at 08:17
  • @Piglet I belive People has free will they can answer or not .It is their choice.I dont want to argue with someone. We havent enough time for this.If u dont like the topic use your vote or report. Dont come here to argue . Have a good day.! – Muhammet PARLAK Jul 12 '17 at 08:42

1 Answers1

1

read an image and apply the same function

import cv2
cascade_src = 'cars.xml'
img = cv2.imread('car.jpg',0)
car_cascade = cv2.CascadeClassifier(cascade_src)
cars = car_cascade.detectMultiScale(img, 1.1, 1)
for (x,y,w,h) in cars:
    cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)      

cv2.imshow('video', img)
cv2.waitKey(0)
Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57
  • Thank u I tried the smiliar one but I dont see the image. The screen is lagging. And Image doesnt show up .I dont know wheres the problem. Something wrong but Dont know where is :( – Muhammet PARLAK Jul 12 '17 at 07:51
  • when you read the image using imread try to use `print(img)` and see that image is being read correctly or not. after that try to print the x, y, w, h points detected and see if they are not None – Arpit Solanki Jul 12 '17 at 08:21
  • When I print image. I see the matrix cordinates. I Also print x y wh cordinates correctly many.But when I want to see image with rectangle nothing comes to screen and its lagging :S – Muhammet PARLAK Jul 12 '17 at 10:40