Crossing Line Detection

47 views
Skip to first unread message

Aurelio Maica

unread,
Sep 13, 2022, 6:55:18 AM9/13/22
to javacv
Good morning, I need to place a line on the frame coming from the camera and perform detections on objects that cross this line. How can I do this? Thanks

Keith Hall

unread,
Sep 15, 2022, 7:50:20 AM9/15/22
to javacv
Are you looking for specific objects as defined in for example the coco dataset
https://tech.amikelive.com/node-718/what-object-categories-labels-are-in-coco-dataset/
or is it a custom list of objects?
If it's a custom list then you would probably need to train your own model. 
Otherwise you can either use the opencv as in this gist here
https://gist.github.com/pyrator/2ba799c062b1ef1913a928a4fcb543e6

you will need to search and download the mask_rcnn_inception_v2_coco_2018_01_28.pbtxt and frozen_inference_graph.pb yourself. This should give you an idea of establishing the rectangles of an object.
Another alternative is to use the Java Tensorflow example here to establish rectangles of object

https://github.com/tensorflow/java-models/tree/master/tensorflow-examples/src/main/java/org/tensorflow/model/examples/cnn/fastrcnn

Aurelio Maica

unread,
Sep 17, 2022, 8:49:49 PM9/17/22
to jav...@googlegroups.com
Thanks for answer. Detecting the object is no problem, the problem is detecting this object after it arrives at a certain point.

--

---
You received this message because you are subscribed to a topic in the Google Groups "javacv" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/javacv/xRYR7i_kOhc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to javacv+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javacv/3d562a50-f75f-43a8-994d-769989b741b0n%40googlegroups.com.

Keith Hall

unread,
Sep 19, 2022, 12:42:51 AM9/19/22
to javacv
Perhaps if you could give a few more details. From your response, I assume you're monitoring a webcam / video for an object, but I may have misunderstood. Is the line horizontal, vertical or at an arbitrary angle. Is the line on the video feed or something you add afterwards?

Aurelio Maica

unread,
Sep 19, 2022, 3:00:54 PM9/19/22
to jav...@googlegroups.com
I monitoring frames from rtsp camera , the line is horizontal. I would like to put the line in the video, and when the car crosses this line, only then start the detection. Here's a print of a real detection



--
Aurélio B. Maicá
Bacharel em Ciência da Computação, Especialista em Redes
WHATSAPP: 54 991952748
CAM_EXIT.jpeg

Keith Hall

unread,
Sep 24, 2022, 5:32:34 AM9/24/22
to javacv
This will draw a horizontal line on the video frame at 200 pixels from the bottom

import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.FrameGrabber;
import org.bytedeco.javacv.OpenCVFrameConverter;
import org.bytedeco.javacv.OpenCVFrameGrabber;
import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.Point;
import org.bytedeco.opencv.opencv_core.Scalar;

import static org.bytedeco.opencv.global.opencv_imgproc.LINE_8;
import static org.bytedeco.opencv.global.opencv_imgproc.LINE_AA;

public class JavaCVVideoLine {

public static void main(String[] params){
try {
OpenCVFrameConverter.ToMat toMatConverter = new OpenCVFrameConverter.ToMat();
OpenCVFrameGrabber openCVFrameGrabber = new OpenCVFrameGrabber(0);
openCVFrameGrabber.start();
Frame frame = openCVFrameGrabber.grab();
CanvasFrame canvasFrame = new CanvasFrame("Video");
canvasFrame.setCanvasSize(frame.imageWidth, frame.imageHeight);
Point p1 = new Point(0, frame.imageHeight-100);
Point p2 = new Point(frame.imageWidth,frame.imageHeight-100);
while (canvasFrame.isVisible() && (frame = openCVFrameGrabber.grab()) != null) {
Mat matImage = toMatConverter.convert(frame);
org.bytedeco.opencv.global.opencv_imgproc.line(matImage,p1,p2, Scalar.MAGENTA, LINE_8, LINE_AA, 0);
canvasFrame.showImage(toMatConverter.convert(matImage));
}
} catch (FrameGrabber.Exception e) {
e.printStackTrace();
}
}
}


So using the YOLONet example you also asked about, you can probably discover from the position of your object with relative to the line or it's position on the screen.

Regards

Keith

Aurelio Maica

unread,
Sep 29, 2022, 6:55:46 PM9/29/22
to jav...@googlegroups.com
really thank you for the answers. One more question, how do I perform my detection when crossing this line?

You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javacv/ec357554-5454-4136-9683-fdb4ed592fe2n%40googlegroups.com.

Aurelio Maica

unread,
Oct 22, 2022, 1:38:44 PM10/22/22
to jav...@googlegroups.com
Good afternoon, how could I create an event when crossing this undrawn line?

Aurelio Maica

unread,
Nov 30, 2022, 1:04:00 PM11/30/22
to jav...@googlegroups.com
please help me create an event when crossing this line friend, sorry to ask so much. Thanks

Em sáb., 24 de set. de 2022 às 06:32, Keith Hall <the.kei...@gmail.com> escreveu:
You received this message because you are subscribed to the Google Groups "javacv" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javacv+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/javacv/ec357554-5454-4136-9683-fdb4ed592fe2n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages