展开全部
去git上面看看源码//先说一下这个32313133353236313431303231363533e78988e69d8331333365643639函数吧
//cvNamedWindow
CV_IMPL int cvNamedWindow(const char* name, int flags){
CV_FUNCNAME("cvNamedWindow");
if (!name)CV_ERROR(CV_StsNullPtr, "NULL name");
HighguiBridge::getInstance().namedWindow(name);
return CV_OK;
}
//而它又需要HighhuiBridge这个类,它有个单例工厂方法
HighguiBridge& HighguiBridge::getInstance(){
static HighguiBridge instance;
return instance;
}
//上面2个函数实际调用这2个成员函数
CvWindow* HighguiBridge::namedWindow(cv::String name) {
CvWindow* window = HighguiBridge::getInstance().findWindowByName(name.c_str());
if (!window)window = createWindow(name);
return window;
}
//创建窗口先是查找有没有已有窗口
CvWindow* HighguiBridge::findWindowByName(cv::String name){
auto search = windowsMap->find(name);
if (search != windowsMap->end())return search->second;
return nullptr;
}
//如果没有会用这个函数创建
CvWindow* HighguiBridge::createWindow(cv::String name){
CvWindow* window = new CvWindow(name);
windowsMap->insert(std::pair<:string>(name, window));
return window;
}
//创建窗口是CvWindow类
class CvWindow{
public:
CvWindow(cv::String name, int flag = CV_WINDOW_NORMAL);
~CvWindow();
/** @brief NOTE: prototype.
Should create button if there is no button with this name already.
*/
void createButton(cv::String name);
/** @brief Creates slider if there is no slider with this name already.
The function creates slider if there is no slider with this name already OR resets
provided values for the existing one.
*/
void createSlider(cv::String name, int* val, int count, CvTrackbarCallback2 on_notify, void* userdata);
/** @brief Updates window image.
@param src Image data object reference.
The function updates window image. If argument is null or image control is not found - does nothing.
*/
void updateImage(CvMat* arr);
/** @brief Returns reference to the trackbar(slider) registered within provided window.
@param name Name of the window.
The function returns reference to the trackbar(slider) registered within provided window.
Returns nullptr if trackbar with specified name is not found or window reference is nullptr.
*/
CvTrackbar* findTrackbarByName(cv::String name);
Page^ getPage();
private:
cv::String name;
// Holds image data in CV format
CvMat* imageData;
// Map of all sliders assigned to this window
std::map<:string>* sliderMap;
// Window contents holder
Page^ page;
// Image control displayed by this window
Image^ imageControl;
// Container for sliders
Panel^ sliderPanel;
// Container for buttons
// TODO: prototype, not available via API
Panel^ buttonPanel;
// Holds image width to arrange other UI elements.
// Required since imageData->width value gets recalculated when processing
int imageWidth;
// Default markup for the container content allowing for proper components placement
static const Platform::String^ markupContent;
// Default Slider size, fallback solution for unexpected edge cases
static const double sliderDefaultWidth;
};
//CvWindwo构造函数为
CvWindow::CvWindow(cv::String name, int flags) : name(name){
this->page = (Page^)Windows::UI::Xaml::Markup::XamlReader::Load(const_cast<:string>(markupContent));
this->sliderMap = new std::map<:string>();
sliderPanel = (Panel^)page->FindName("cvTrackbar");
imageControl = (Image^)page->FindName("cvImage");
buttonPanel = (Panel^)page->FindName("cvButton");
// Required to adapt controls to the size of the image.
// System calculates image control width first, after that we can
// update other controls
imageControl->Loaded += ref new Windows::UI::Xaml::RoutedEventHandler(
[=](Platform::Object^ sender,
Windows::UI::Xaml::RoutedEventArgs^ e){
// Need to update sliders with appropriate width
for(auto iter=sliderMap->begin();iter!=sliderMap->end();++iter){
iter->second->getSlider()->Width = imageControl->ActualWidth;
}
// Need to update buttons with appropriate width
// TODO: implement when adding buttons
});
}