1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 07:43:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Smorkalov
2025-07-17 18:23:51 +03:00
140 changed files with 2891 additions and 1208 deletions
+5 -2
View File
@@ -12,12 +12,13 @@ static void help(char** argv)
printf("\nShow off image morphology: erosion, dialation, open and close\n"
"Call:\n %s [image]\n"
"This program also shows use of rect, ellipse and cross kernels\n\n", argv[0]);
"This program also shows use of rect, ellipse, cross and diamond kernels\n\n", argv[0]);
printf( "Hot keys: \n"
"\tESC - quit the program\n"
"\tr - use rectangle structuring element\n"
"\te - use elliptic structuring element\n"
"\tc - use cross-shaped structuring element\n"
"\td - use diamond-shaped structuring element\n"
"\tSPACE - loop through all the options\n" );
}
@@ -101,8 +102,10 @@ int main( int argc, char** argv )
element_shape = MORPH_RECT;
else if( c == 'c' )
element_shape = MORPH_CROSS;
else if( c == 'd' )
element_shape = MORPH_DIAMOND;
else if( c == ' ' )
element_shape = (element_shape + 1) % 3;
element_shape = (element_shape + 1) % 4;
}
return 0;
+1 -1
View File
@@ -10,7 +10,7 @@ using namespace std;
// {
// cout << "\nThis program demonstrates kmeans clustering.\n"
// "It generates an image with random points, then assigns a random number of cluster\n"
// "centers and uses kmeans to move those cluster centers to their representitive location\n"
// "centers and uses kmeans to move those cluster centers to their representative location\n"
// "Call\n"
// "./kmeans\n" << endl;
// }
@@ -66,20 +66,20 @@ int main( int argc, char** argv )
Mat hist_base, hist_half_down, hist_test1, hist_test2;
calcHist( &hsv_base, 1, channels, Mat(), hist_base, 2, histSize, ranges, true, false );
normalize( hist_base, hist_base, 0, 1, NORM_MINMAX, -1, Mat() );
normalize( hist_base, hist_base, 1, 0, NORM_L1, -1, Mat() );
calcHist( &hsv_half_down, 1, channels, Mat(), hist_half_down, 2, histSize, ranges, true, false );
normalize( hist_half_down, hist_half_down, 0, 1, NORM_MINMAX, -1, Mat() );
normalize( hist_half_down, hist_half_down, 1, 0, NORM_L1, -1, Mat() );
calcHist( &hsv_test1, 1, channels, Mat(), hist_test1, 2, histSize, ranges, true, false );
normalize( hist_test1, hist_test1, 0, 1, NORM_MINMAX, -1, Mat() );
normalize( hist_test1, hist_test1, 1, 0, NORM_L1, -1, Mat() );
calcHist( &hsv_test2, 1, channels, Mat(), hist_test2, 2, histSize, ranges, true, false );
normalize( hist_test2, hist_test2, 0, 1, NORM_MINMAX, -1, Mat() );
normalize( hist_test2, hist_test2, 1, 0, NORM_L1, -1, Mat() );
//! [Calculate the histograms for the HSV images]
//! [Apply the histogram comparison methods]
for( int compare_method = 0; compare_method < 4; compare_method++ )
for( int compare_method = 0; compare_method < 6; compare_method++ )
{
double base_base = compareHist( hist_base, hist_base, compare_method );
double base_half = compareHist( hist_base, hist_half_down, compare_method );
@@ -18,7 +18,7 @@ int erosion_elem = 0;
int erosion_size = 0;
int dilation_elem = 0;
int dilation_size = 0;
int const max_elem = 2;
int const max_elem = 3;
int const max_kernel_size = 21;
/** Function Headers */
@@ -47,7 +47,7 @@ int main( int argc, char** argv )
moveWindow( "Dilation Demo", src.cols, 0 );
/// Create Erosion Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Erosion Demo",
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse \n 3: Diamond", "Erosion Demo",
&erosion_elem, max_elem,
Erosion );
@@ -56,7 +56,7 @@ int main( int argc, char** argv )
Erosion );
/// Create Dilation Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Dilation Demo",
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse \n 3: Diamond", "Dilation Demo",
&dilation_elem, max_elem,
Dilation );
@@ -83,6 +83,7 @@ void Erosion( int, void* )
if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
else if( erosion_elem == 3) { erosion_type = MORPH_DIAMOND; }
//![kernel]
Mat element = getStructuringElement( erosion_type,
@@ -106,6 +107,7 @@ void Dilation( int, void* )
if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
else if( dilation_elem == 3) { dilation_type = MORPH_DIAMOND; }
Mat element = getStructuringElement( dilation_type,
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
@@ -18,7 +18,7 @@ int morph_elem = 0;
int morph_size = 0;
int morph_operator = 0;
int const max_operator = 4;
int const max_elem = 2;
int const max_elem = 3;
int const max_kernel_size = 21;
const char* window_name = "Morphology Transformations Demo";
@@ -54,7 +54,7 @@ int main( int argc, char** argv )
//![create_trackbar2]
/// Create Trackbar to select kernel type
createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse", window_name,
createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse - 3: Diamond", window_name,
&morph_elem, max_elem,
Morphology_Operations );
//![create_trackbar2]
@@ -55,7 +55,7 @@ int main(void)
thrust::sequence(idxBegin, idxEnd);
// Fill the key channel with random numbers between 0 and 10. A counting iterator is used here to give an integer value for each location as an input to prg::operator()
thrust::transform(thrust::make_counting_iterator(0), thrust::make_counting_iterator(d_data.cols), keyBegin, prg(0, 10));
// Sort the key channel and index channel such that the keys and indecies stay together
// Sort the key channel and index channel such that the keys and indices stay together
thrust::sort_by_key(keyBegin, keyEnd, idxBegin);
cv::Mat h_idx(d_data);
+1 -1
View File
@@ -373,7 +373,7 @@ public:
r = m_pD3D11SwapChain->Present(0, 0);
if (FAILED(r))
{
throw std::runtime_error("switch betweem fronat and back buffers failed!");
throw std::runtime_error("switch between fronat and back buffers failed!");
}
} // try
+1 -1
View File
@@ -267,4 +267,4 @@ def main():
if __name__ == '__main__':
args = get_args_parser()
main()
main()
+7 -2
View File
@@ -101,8 +101,12 @@ int App::run()
element_shape = MORPH_CROSS;
break;
case 'd':
element_shape = MORPH_DIAMOND;
break;
case ' ':
element_shape = (element_shape + 1) % 3;
element_shape = (element_shape + 1) % 4;
break;
}
}
@@ -113,13 +117,14 @@ void App::help()
cout << "Show off image morphology: erosion, dialation, open and close \n";
cout << "Call: \n";
cout << " gpu-example-morphology [image] \n";
cout << "This program also shows use of rect, ellipse and cross kernels \n" << endl;
cout << "This program also shows use of rect, ellipse, cross and diamond kernels \n" << endl;
cout << "Hot keys: \n";
cout << "\tESC - quit the program \n";
cout << "\tr - use rectangle structuring element \n";
cout << "\te - use elliptic structuring element \n";
cout << "\tc - use cross-shaped structuring element \n";
cout << "\td - use diamond-shaped structuring element \n";
cout << "\tSPACE - loop through all the options \n" << endl;
}
@@ -52,23 +52,23 @@ class CompareHist {
List<Mat> hsvBaseList = Arrays.asList(hsvBase);
Imgproc.calcHist(hsvBaseList, new MatOfInt(channels), new Mat(), histBase, new MatOfInt(histSize), new MatOfFloat(ranges), false);
Core.normalize(histBase, histBase, 0, 1, Core.NORM_MINMAX);
Core.normalize(histBase, histBase, 1, 0, Core.NORM_L1);
List<Mat> hsvHalfDownList = Arrays.asList(hsvHalfDown);
Imgproc.calcHist(hsvHalfDownList, new MatOfInt(channels), new Mat(), histHalfDown, new MatOfInt(histSize), new MatOfFloat(ranges), false);
Core.normalize(histHalfDown, histHalfDown, 0, 1, Core.NORM_MINMAX);
Core.normalize(histHalfDown, histHalfDown, 1, 0, Core.NORM_L1);
List<Mat> hsvTest1List = Arrays.asList(hsvTest1);
Imgproc.calcHist(hsvTest1List, new MatOfInt(channels), new Mat(), histTest1, new MatOfInt(histSize), new MatOfFloat(ranges), false);
Core.normalize(histTest1, histTest1, 0, 1, Core.NORM_MINMAX);
Core.normalize(histTest1, histTest1, 1, 0, Core.NORM_L1);
List<Mat> hsvTest2List = Arrays.asList(hsvTest2);
Imgproc.calcHist(hsvTest2List, new MatOfInt(channels), new Mat(), histTest2, new MatOfInt(histSize), new MatOfFloat(ranges), false);
Core.normalize(histTest2, histTest2, 0, 1, Core.NORM_MINMAX);
Core.normalize(histTest2, histTest2, 1, 0, Core.NORM_L1);
//! [Calculate the histograms for the HSV images]
//! [Apply the histogram comparison methods]
for( int compareMethod = 0; compareMethod < 4; compareMethod++ ) {
for( int compareMethod = 0; compareMethod < 6; compareMethod++ ) {
double baseBase = Imgproc.compareHist( histBase, histBase, compareMethod );
double baseHalf = Imgproc.compareHist( histBase, histHalfDown, compareMethod );
double baseTest1 = Imgproc.compareHist( histBase, histTest1, compareMethod );
@@ -23,7 +23,7 @@ import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class MorphologyDemo1 {
private static final String[] ELEMENT_TYPE = { "Rectangle", "Cross", "Ellipse" };
private static final String[] ELEMENT_TYPE = { "Rectangle", "Cross", "Ellipse", "Diamond" };
private static final String[] MORPH_OP = { "Erosion", "Dilatation" };
private static final int MAX_KERNEL_SIZE = 21;
private Mat matImgSrc;
@@ -79,6 +79,8 @@ public class MorphologyDemo1 {
elementType = Imgproc.MORPH_CROSS;
} else if (cb.getSelectedIndex() == 2) {
elementType = Imgproc.MORPH_ELLIPSE;
} else if (cb.getSelectedIndex() == 3) {
elementType = Imgproc.MORPH_DIAMOND;
}
update();
}
+1 -1
View File
@@ -35,7 +35,7 @@ def main():
cv.imshow('original', img)
modes = cycle(['erode/dilate', 'open/close', 'blackhat/tophat', 'gradient'])
str_modes = cycle(['ellipse', 'rect', 'cross'])
str_modes = cycle(['ellipse', 'rect', 'cross', 'diamond'])
cur_mode = next(modes)
cur_str_mode = next(str_modes)
@@ -45,20 +45,20 @@ channels = [0, 1]
## [Calculate the histograms for the HSV images]
hist_base = cv.calcHist([hsv_base], channels, None, histSize, ranges, accumulate=False)
cv.normalize(hist_base, hist_base, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
cv.normalize(hist_base, hist_base, alpha=1, beta=0, norm_type=cv.NORM_L1)
hist_half_down = cv.calcHist([hsv_half_down], channels, None, histSize, ranges, accumulate=False)
cv.normalize(hist_half_down, hist_half_down, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
cv.normalize(hist_half_down, hist_half_down, alpha=1, beta=0, norm_type=cv.NORM_L1)
hist_test1 = cv.calcHist([hsv_test1], channels, None, histSize, ranges, accumulate=False)
cv.normalize(hist_test1, hist_test1, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
cv.normalize(hist_test1, hist_test1, alpha=1, beta=0, norm_type=cv.NORM_L1)
hist_test2 = cv.calcHist([hsv_test2], channels, None, histSize, ranges, accumulate=False)
cv.normalize(hist_test2, hist_test2, alpha=0, beta=1, norm_type=cv.NORM_MINMAX)
cv.normalize(hist_test2, hist_test2, alpha=1, beta=0, norm_type=cv.NORM_L1)
## [Calculate the histograms for the HSV images]
## [Apply the histogram comparison methods]
for compare_method in range(4):
for compare_method in range(6):
base_base = cv.compareHist(hist_base, hist_base, compare_method)
base_half = cv.compareHist(hist_base, hist_half_down, compare_method)
base_test1 = cv.compareHist(hist_base, hist_test1, compare_method)
@@ -5,9 +5,9 @@ import argparse
src = None
erosion_size = 0
max_elem = 2
max_elem = 3
max_kernel_size = 21
title_trackbar_element_shape = 'Element:\n 0: Rect \n 1: Cross \n 2: Ellipse'
title_trackbar_element_shape = 'Element:\n 0: Rect \n 1: Cross \n 2: Ellipse \n 3: Diamond'
title_trackbar_kernel_size = 'Kernel size:\n 2n +1'
title_erosion_window = 'Erosion Demo'
title_dilation_window = 'Dilation Demo'
@@ -42,6 +42,8 @@ def morph_shape(val):
return cv.MORPH_CROSS
elif val == 2:
return cv.MORPH_ELLIPSE
elif val == 3:
return cv.MORPH_DIAMOND
## [erosion]
@@ -5,10 +5,10 @@ import argparse
morph_size = 0
max_operator = 4
max_elem = 2
max_elem = 3
max_kernel_size = 21
title_trackbar_operator_type = 'Operator:\n 0: Opening - 1: Closing \n 2: Gradient - 3: Top Hat \n 4: Black Hat'
title_trackbar_element_type = 'Element:\n 0: Rect - 1: Cross - 2: Ellipse'
title_trackbar_element_type = 'Element:\n 0: Rect - 1: Cross - 2: Ellipse - 3: Diamond'
title_trackbar_kernel_size = 'Kernel size:\n 2n + 1'
title_window = 'Morphology Transformations Demo'
morph_op_dic = {0: cv.MORPH_OPEN, 1: cv.MORPH_CLOSE, 2: cv.MORPH_GRADIENT, 3: cv.MORPH_TOPHAT, 4: cv.MORPH_BLACKHAT}
@@ -24,6 +24,8 @@ def morphology_operations(val):
morph_elem = cv.MORPH_CROSS
elif val_type == 2:
morph_elem = cv.MORPH_ELLIPSE
elif val_type == 3:
morph_elem = cv.MORPH_DIAMOND
element = cv.getStructuringElement(morph_elem, (2*morph_size + 1, 2*morph_size+1), (morph_size, morph_size))
operation = morph_op_dic[morph_operator]
+1 -1
View File
@@ -23,7 +23,7 @@ if(NOT SYCL_FOUND AND NOT OPENCV_SKIP_SAMPLES_SYCL_ONEDNN)
if(NOT DEFINED DNNLROOT AND DEFINED ENV{DNNLROOT})
set(DNNLROOT "$ENV{DNNLROOT}")
endif()
# Some verions of called script violate CMake policy and may emit unrecoverable CMake errors
# Some versions of called script violate CMake policy and may emit unrecoverable CMake errors
# Use OPENCV_SKIP_SAMPLES_SYCL=1 / OPENCV_SKIP_SAMPLES_SYCL_ONEDNN to bypass this
find_package(dnnl CONFIG QUIET HINTS "${DNNLROOT}")
endif()
@@ -1047,7 +1047,7 @@ done:
// Create a partial media type from our list.
//
// dwTypeIndex: Index into the list of peferred media types.
// dwTypeIndex: Index into the list of preferred media types.
// ppmt: Receives a pointer to the media type.
HRESULT OcvImageManipulations::OnGetPartialType(DWORD dwTypeIndex, IMFMediaType **ppmt)