OpenCV: drawing an image

I am working on a program using the OpenCV library (although I am completely zero on it). One of the things I need to do is draw an image. I looked at the OpenCV drawing functions and they all look pretty simple (Circle, Line, etc.), however the program will not compile! It says it’s for sure: error C3861: Line: identifier not found. Is there something that I have not installed? I used the tutorial at 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 to work as soon as possible!

+3
source share
3 answers

The line drawing function in the OpenCV C API is called cvLine, not Line.

+4
source

I think you fell victim to the following common mistake: C includes #include <opencv/core.h>, etc., whereas C ++ includes:

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <oppencv2/highgui/highgui.hpp>

Turn them on to draw and display the image. Use using namespace cv;, then you do not need to write cv::linesimply line, and everything will work fine.
I had to fight the same problem when I started .;)

(And btw use cv::Matfor C ++.)

+1
source

Now you can easily draw OpenCV images. To do this, you need to call the function setMouseCallback(‘window_name’,image_name)on opencv. After that, you can easily handle the mouse callback function on your images. Then you need to detect events cv2.EVENT_LBUTTONDOWN, cv2.EVENT_MOUSEMOVE and cv2.EVENT_LBUTTONUP. By checking the correct logical condition, you need to decide how you like to interact with 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 more details see the link: How to draw OpenCV images and save the image.

Conclusion:

enter image description here

0
source

Source: https://habr.com/ru/post/1761488/


All Articles