I want to binarize with opencv and display specific coordinates.

Asked 2 years ago, Updated 2 years ago, 111 views

The following errors do not disappear!

  • cv::MATh_image expression requires a pointer type

os windows 10
Compiler visual studio 2017

Thank you for your cooperation.
Cited from:
https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1292659747
http://kivantium.hateblo.jp/entry/20120822/p1
Kinect Practical Program Sugiuraji

#include "stdafx.h"
# include <Windows.h>
# include <NuiApi.h>

# include <opencv2/opencv.hpp>
            while(1){
                drawRgbImage(image);

            cv::Math_image;
            cv::flip(image,h_image,1);

            // Convert RGB image to HSV image
            cv::Mathsv, extracted;
            cv::cvtColor(h_image, hsv, CV_RGB2HSV); // CV_BGR2HSV if camera image is BGR
                                                    // Extract the area where the color ranges from 100<=H<=120,80<=S<=255,80<=V<=255
                                                    // Adjust the color range to match the color of the object you want to extract.
            cv::Scalar hsv_min = cv::Scalar(120,80,80);
            cv::Scalar hsv_max = cv::Scalar(130,255,255);
            cv::inRange(hsv,hsv_min,hsv_max,extracted);

            // labeling execution
            cv::MatlabelImg,stats,centroids;
            intnLabels=cv::connectedComponentsWithStats(extracted, labelImg, stats, centroids);

            // Display image
            cv::imshow("kinect Sample", h_image);

            // White out
            using namespace std;

            // Input file, output file name
            const char*srcimgfname("g:\\testimg\\test.bmp");
            const char*rstimgfname("g:\\testimg\\result.bmp");

            IplImage* srcimg=cvLoadImage(srcimgfname, CV_LOAD_IMAGE_COLOR);
            // Copy the input image and paint it white
            IplImage*rstimg=cvCloneImage(srcimg);

                cvRectangle(srcimg, cvPoint(0,0),
                    cvPoint(h_image->width, srcimg->height),
                    CV_RGB (0xff, 0xff, 0xff), CV_FILLED);

                // Pointer to image data
                unsigned char*srcpt=(unsigned char*)srcimg ->imageData;// input image
                unsigned char*rstpt=(unsigned char*)rstimg->imageData;// Output image

                for(inty=0;y<srcimg->height;++y){
                    for(intx=0;x<srcimg->width;++x){
                        if((srcpt[0]==0x00)&&//B
                            (srcpt[1]==0x00)&//G 
                            (srcpt[2]==0xff)) {//R
                                                  // Draw a red circle with radius 3 and output coordinate values
                            cvCircle(rstimg, cvPoint(x,y), 3, CV_RGB(0xff,0,0));
                            printf("(%d,%d)=\n",x,y);
                        }
                // Move the pointer to the next pixel
                        srcpt+=srcimg->nChannels;
                        rstpt+=rstimg->nChannels;
                    }
                }



                cvSaveImage(rstimgfname, rstimg);

                return 0;
            }

                    }
    }

c++ opencv kinect

2022-09-30 21:36

2 Answers

The following errors do not disappear!
The cv::MATh_image expression requires a pointer type

There is no description in the question, but is this an error in the code h_image->width below?

cvRectangle(srcimg, cvPoint(0,0),
            cvPoint(h_image->width, srcimg->height),
            CV_RGB (0xff, 0xff, 0xff), CV_FILLED);

Because the variable h_image is of the cv::Mat class type, it is not pointer type as the error message indicates.If でimage width 」 is required, it must be written as h_image.cols or h_image.size().width.

It has nothing to do with the title, but it seems to be a mixture of old and new OpenCV versions.The IplImage type is not recommended, especially because it is a relic from the old OpenCV 1.0 era.Consider using cv::Mat by default (many new OpenCV features do not support IplImage)


2022-09-30 21:36

  • Identifier srcimg is not defined
  • Identifier "rstimg" is not defined
  • Identifier "rstimgfname" is not defined

These three errors are caused by a variable with this name not defined.These variables are used in the middle of the program, but they have not been defined before that.Pre-editing code defines these variables (except that the main function has started to be defined in strange places), but now that part has been edited, it has been erased.


2022-09-30 21:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.