How to detect canny edge and integral projection on a real time webcam using c# aforge? -
"i have been trying detect canny edge on image , has been successful, don't know how detect edge if want real time, here code, has no error canny window can't processed
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; //using komcit; using system.drawing.imaging; using system.io; using system.timers; using aforge; using aforge.imaging.filters; using aforge.video.directshow; using system.threading; namespace canny_video { public partial class form1 : form { public form1() { initializecomponent(); } private filterinfocollection capturedevice; private videocapturedevice finalframe; void finalframe_newframe(object sender, aforge.video.newframeeventargs eventargs) { camerabox.image = (bitmap)eventargs.frame.clone(); } private static image resizeimage(image imgtoresize, size size) { return (image)(new bitmap(imgtoresize, size)); } private void form1_load(object sender, eventargs e) { //timer1.enabled = true; capturedevice = new filterinfocollection(filtercategory.videoinputdevice); foreach (filterinfo device in capturedevice) { listdevice.items.add(device.name); } listdevice.selectedindex = 0; finalframe = new videocapturedevice(); } private void start_click(object sender, eventargs e) { finalframe = new videocapturedevice(capturedevice[listdevice.selectedindex].monikerstring); finalframe.newframe += new aforge.video.newframeeventhandler(finalframe_newframe); finalframe.start(); //cannybox.image = (bitmap)camerabox.image.clone(); //capture image bitmap //bitmap gambar = new bitmap(camerabox.image); bitmap gambar = new bitmap(camerabox.image); grayscale gray = new grayscale(0.2125, 0.7154, 0.0721); cannyedgedetector cany = new cannyedgedetector(0, 70); bitmap hasil = cany.apply(gray.apply(gambar)); // blobsfiltering blob = new blobsfiltering(0, 0, 20, 20); //bitmap hasil = blob.apply(gray.apply(gambar)); //cannybox.width = gambar.width; //cannybox.height = gambar.height; cannybox.image = hasil; } private void form1_formclosing(object sender, formclosingeventargs e) { if (finalframe.isrunning == true) { finalframe.stop(); } } } }
"
my problem above solved, thank :) have problem on integral projection, didn't know how though. please help, thank in advance
some comments:
- your 2 private variables confusingly named.
capturedevice
collection of capture devices on computer, whilefinalframe
capture device. - you not canny edges on bitmap upon reception.
- the newframe event handler runs in streaming thread, should use
.begininvoke
in there make usable ui thread.
what may do:
- inside _newframe handler, use begininvoke transfer cloned image
processcameraimage
method (that hence run on ui thread). - apply canny edge detection within method.
- then assign result picture box.
note: don't know how cpu heavy canny edge detection is. if it's costly, doing on ui thread may block user interaction. in case within streaming thread , transfer processed image display. depending on time takes, may force camera lower framerate.
Comments
Post a Comment