java - Call method when Key pressed -
i working opencv , video capture want call method takes frame based on key press. not sure doing wrong when run program when press space key image isn't being captured. here code:
public class videocap implements keylistener{ getcontours takeframe = new getcontours(); static{ system.loadlibrary(core.native_library_name); } videocapture cap; mat2image mat2img = new mat2image(); mat copy = new mat(); videocap(){ cap = new videocapture(); cap.open(0); } int frames = 0; /*int savedcount = 0; //keep track of saved frames string[] photos = {"first.png","second.png","third.png","forth.png", "fifth.png","sixth.png","seventh.png","eigth.png","ninth.png"}; */ boolean captured = false; bufferedimage getoneframe() { frames++; cap.read(mat2img.mat); mat2img.mat = takeframe.captureframe(mat2img.mat); if(captured == true){ mat2img.mat = takeframe.captureframe(mat2img.mat); system.out.println("written!!!"); imgcodecs.imwrite("first.png", mat2img.mat); system.exit(0); } return mat2img.getimage(mat2img.mat); } @override public void keypressed(keyevent e) { if(e.getkeycode() == keyevent.vk_space){ captured = true; } }
Comments
Post a Comment