I am working on a program using the OpenCV library (though I am quite a noob on it). One of the things I need to do is to draw on the image. I looked at the OpenCV drawing functions and they all seem pretty simple (Circle, Line, etc), however the program won't compile! It says this to be exact: error C3861: 'Line': identifier not found. Is there something I haven't installed? I used the tutorial on http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2008 to install OpenCV on Visual Studio 2008 and so far this is the only real problem I have. Please help me! I need this program working as soon as possible!
3 Answers
-
Ok... That was easy. Nothing was said in the site -_- http://opencv.willowgarage.com/documentation/python/drawing_functions.html Thank you very much! – Juls Aug 25 '10 at 11:46
-
@Juls The link you posted is for the Python documentation, which is why the function names are different. – Phil Ross Aug 25 '10 at 12:12
-
1+1 Accurate. Juls, don't forget to vote up on his answer or accept it as the official solution. – karlphillip Aug 25 '10 at 13:27
I think you have fallen victim of the following common mistake:
C includes are in #include <opencv/core.h>
etc, whereas
C++ includes are:
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <oppencv2/highgui/highgui.hpp>
Include these for drawing and showing the image. Use using namespace cv;
then
you don't have to write cv::line
just line
and everything will be working fine.
I had to battle with the very same problem when I began. ;)
(And btw use cv::Mat
for c++.)

- 11,846
- 12
- 66
- 91
You can now easily paint on OpenCV images. For this you need to call the setMouseCallback(‘window_name’,image_name)
function on opencv. After that you can easily handle the Mouse Callback Function upon your images. Then you need to detect the cv2.EVENT_LBUTTONDOWN, cv2.EVENT_MOUSEMOVE and cv2.EVENT_LBUTTONUP
events. By checking the proper boolean condition you need to decide how you like to interact with the OpenCV images.
def paint_draw(event,former_x,former_y,flags,param):
global current_former_x,current_former_y,drawing, mode
if event==cv2.EVENT_LBUTTONDOWN:
drawing=True
current_former_x,current_former_y=former_x,former_y
elif event==cv2.EVENT_MOUSEMOVE:
if drawing==True:
if mode==True:
cv2.line(image,(current_former_x,current_former_y),(former_x,former_y),(0,0,255),5)
current_former_x = former_x
current_former_y = former_y
elif event==cv2.EVENT_LBUTTONUP:
drawing=False
if mode==True:
cv2.line(image,(current_former_x,current_former_y),(former_x,former_y),(0,0,255),5)
current_former_x = former_x
current_former_y = former_y
return former_x,former_y
For details you can see link: How to Paint on OpenCV Images and Save the Image
Output:

- 61
- 5