Automatic Image testing framework

Source: Internet
Author: User

Recently, due to the need to use image matching algorithms for the Kinect project, I have seen a lot of papers on the internet, and I don't know which ones are suitable for me at the moment, as a result, I think we should test these methods to find a good method that suits me. However, the problem arises. It is unrealistic to experiment with so many algorithms one by one. After careful consideration, I made up my mind to write an automatic framework to accelerate my testing speed. This framework defines three basic classes: imagegen, skindetect, and action.

Imagegen: automatically generates the image to be detected. The interface is as follows:

class ImageGen{public:virtual IplImage* operator()() = 0;virtual IplImage* getImage() = 0;virtual void  reset() = 0;};

The operator () function and getimage () function should be consistent, mainly to obtain images. To facilitate interaction with other classes, the image format generated here should be BGR, if other detection methods use other image formats, you can perform proper conversion, reset () to reset the pointer and obtain the image again.

This is why the class is defined because of the extension problem, so that no matter where the image comes from, the framework can be used as long as it complies with the interface standard.


Skindetect: Image Detection class. This class is mainly used to detect images. Because my tests are related to skin color detection, this class is related to skin color detection. To expand, can be further abstracted to become a more basic class: imagedetect ..., the interface is as follows:

Class skindetect {public: skindetect (): _ skin_counts (0), _ goods_counts (0) {}// the row and Col of SRC and Res are consistent, the SRC format is BGR // The result is stored in res. Virtual bool detected (iplimage * SRC, iplimage * res) = 0; // The parameter is stringized, this helps you determine the current parameter value. Virtual STD: String tostring () = 0; virtual ~ Skindetect () {} size_t getskincounts () {return _ skin_counts;} size_t getgoodscounts () {return _ goods_counts;} // The meaning of the gray level in the result image: static const int bg_value = 0; // background gray value static const int skin_value = 255; // skin gray value static const int goods_value = 100; // item gray value protected: size_t _ skin_counts; size_t _ goods_counts ;};///@~

Goods_counts is defined mainly because this experiment has something to do with products, so we put it into the base class. It is worth noting that the static constants bg_value, skin_value, and goods_value are also defined, Because I divide the image into three parts: Skin, product, and background. Different Parts correspond to different colors.

Action: Action class. The function of this class is to perform the corresponding action when detecting that the return value is true. The interface is as follows:

/*************************************** * ******** Call the method of this class for processing when the condition is determined ******************* * ***************************/class action {public: virtual void operator () (iplimage * SRC, iplimage * res) = 0; virtual ~ Action (){};};
There is only one public interface: Operator (). The first parameter is the original image, and the second parameter is the detection result.


The last class is judgerframework, which references the above class for automatic detection, as shown below:

class JudgerFrameWork{public:JudgerFrameWork( ImageGen& img_gen, SkinDetect& skin_detect, Action& action ): _img_gen(img_gen), _skin_detect(skin_detect), _action(action){}void start(){for( IplImage* image = _img_gen.getImage(); image != NULL; image = _img_gen.getImage() ){IplImage* res = cvCreateImage( cvGetSize(image), IPL_DEPTH_8U, 1 );if( _skin_detect.detected( image, res ) ){_action( image, res );std::cout << "goods count:" << _skin_detect.getGoodsCounts() << std::endl;std::cout << "skins count:" << _skin_detect.getSkinCounts()  << std::endl;}}}private:ImageGen& _img_gen;SkinDetect& _skin_detect;Action& _action;};
The main task is to create the corresponding object and construct the judgerframework object. After constructing the object, you only need to call the function: Start () to complete all the actions.


The Framework was modified N times before and after it was set up, mainly because the interface was difficult to control and sometimes it was difficult to coordinate the function allocation. In addition, if the setting is too abstract, it increases the complexity of development. If the abstraction is not enough, it is not conducive to expansion.

I can't help but sigh: I have learned a lot about development, and I have learned a lot about interface design!

Automatic Image testing framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.