Ask Your Question
0

How do you save images of detected objects?

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

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.

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

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

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

Comments

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

kingpin gravatar imagekingpin ( 2014-12-29 19:00:06 -0600 )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 -0600 )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 -0600 )edit
3

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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 644 times

Last updated: Dec 29 '14