Ask Your Question

How do you save images of detected objects?

asked 2014-12-29 14:54:09 -0500

kingpin gravatar image

hello all,

i am trying to add "if logic" to the opencv face detection code such that when a face is detected through a camera or webcam, an image of the detected face is save to a pre-determined file path on the controller or computer such as C:\Users\Public\Desktop.

i have looked everywhere for examples of anything that can help but i cant find anything.

if anyone knows any codes, research articles, websites, people i can contact, that would be very helpful.


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-12-29 18:11:15 -0500

unxnut gravatar image

Use the imwrite function. If the image is cv::Mat image, you can save it by using

imwrite ( filename, image );
edit flag offensive delete link more


I am not sure I understand your answer. Could you explain more?

kingpin gravatar imagekingpin ( 2014-12-29 19:00:06 -0500 )edit

The function to save an image is imwrite. Is that what you are looking for? Or do you want something else?

unxnut gravatar imageunxnut ( 2014-12-29 19:47:28 -0500 )edit

I'll have to look in into the imwrite function more, thanks. Do you know how to designate the file path to where I want the image saved to in the code?

kingpin gravatar imagekingpin ( 2014-12-29 20:57:08 -0500 )edit

You should be able to specify the complete path and append the filename to it. For example:

std::string file_path = "c:\dir1\dir2\"
std::string file_name = "filename.jpg"
std::string save_location = file_path + file_name;
imwrite ( save_location, image );
unxnut gravatar imageunxnut ( 2014-12-29 21:01:41 -0500 )edit

Thanks that should be very helpful. Do you know how I could go about implementing the actual "if then" logic in the code? By that I mean if face detected, then take picture and save to file path?

kingpin gravatar imagekingpin ( 2014-12-30 17:17:07 -0500 )edit

Are you looking for code to detect a face? If so, check out Haar cascades. Otherwise, tell us what you have done so far and we can go from there.

unxnut gravatar imageunxnut ( 2014-12-30 18:33:21 -0500 )edit

No I already have the code detecting a face, I am just trying to add the logic such that an image of detected faces is saved to the controller as previously stated.What you have given me in regards to actually saving the image is very helpful. Now all I need help with is having the program only take and save images of faces that are detected.

kingpin gravatar imagekingpin ( 2014-12-30 18:45:18 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-12-29 14:54:09 -0500

Seen: 228 times

Last updated: Dec 29 '14