Ask Your Question
0

How to copy recognized image (only recognize image not full image)

asked 2016-05-26 10:55:22 -0500

Ryan_coder gravatar image
 private DaemonThread myThread = null;
int count = 0;
VideoCapture webSource = null;
Mat frame = new Mat();
MatOfByte mem = new MatOfByte();
CascadeClassifier faceDetector = new CascadeClassifier(FaceCrp.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
MatOfRect faceDetections = new MatOfRect();
public Point point1,point2; 
Image img1;
Rect rect;

///

class DaemonThread implements Runnable {

    protected volatile boolean runnable = false;

    @Override
    public void run() {
        synchronized (this) {
            while (runnable) {
                if (webSource.grab()) {
                    try {
                        webSource.retrieve(frame);
                        Graphics g = jPanel1.getGraphics();
                        faceDetector.detectMultiScale(frame, faceDetections);
                        //Highgui.imwrite("d:/capture5.jpg", frame); No face detection till
                        //Rect rect = new Rect(faceDetections.toArray(frame));
                        for (Rect rect : faceDetections.toArray()) {
                           System.out.println("ttt");

                           Core.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                                    new Scalar(0, 255,0));
                           Highgui.imwrite("d:/capture6.jpg", frame);

                        }

                        Highgui.imencode(".bmp", frame, mem);
                        Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
                        BufferedImage buff = (BufferedImage) im;
                        if (g.drawImage(buff, 0, 0, getWidth(), getHeight()-150 , 0, 0, buff.getWidth(), buff.getHeight(), null))
                        {
                            //Highgui.imwrite("d:/capture2.jpg", frame);

                            System.out.println("ttt");
                            if (runnable == false) {
                                System.out.println("Paused ..... ");
                                this.wait();
                            }
                        }

                    } catch (Exception ex) {
                        System.out.println("Error");
                    }
                }
            }
        }
    }

}

Thanks in advance

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-05-26 11:49:35 -0500

berak gravatar image

updated 2016-05-26 13:03:22 -0500

you got this loop:

 for (Rect rect : faceDetections.toArray()) {
        // now, instead of writing the whole image to disk,
        // only write the (face) cropped  portion:
        Mat cropped = frame.submat(rect);
        Highgui.imwrite("d:/capture6.jpg", cropped);
        // also, please do this, *before* drawing more stuff into 'frame'
       ...
edit flag offensive delete link more

Comments

Thanks break for reply but its not working .. now it will not taking any snapshot .. or cam also not visible .. Error: Mat cropped = frame.subrect(rect);

Ryan_coder gravatar imageRyan_coder ( 2016-05-26 12:33:33 -0500 )edit

please, the whole errormsg..

berak gravatar imageberak ( 2016-05-26 12:40:47 -0500 )edit

it will not giving any error message but video is stop and also face detection is not work, exception msg is print Erro: method subrect(rect) , variable frame of type mat

Ryan_coder gravatar imageRyan_coder ( 2016-05-26 12:50:59 -0500 )edit

bear with me, no actual java env on this box, it's submat , not subrect

berak gravatar imageberak ( 2016-05-26 13:02:40 -0500 )edit

ohh m sorry bro thanks a lot .. its working

Ryan_coder gravatar imageRyan_coder ( 2016-05-26 13:05:27 -0500 )edit

again, apologies, original error was onmy side, thanks for pointing out !

berak gravatar imageberak ( 2016-05-26 13:17:55 -0500 )edit

Break can you help me more ?? i have many question related to my project, and i'm using opencv which is new for me .. or we cam talk on mail .. Thanks

Ryan_coder gravatar imageRyan_coder ( 2016-05-26 13:24:59 -0500 )edit
1

i'll sure try to help you, but better keep it on this QA site, since there's more helpful eyeballs here.

(just dare to ask a new question, that's what this site is for ... )

berak gravatar imageberak ( 2016-05-26 13:41:30 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-05-26 10:55:22 -0500

Seen: 231 times

Last updated: May 26 '16