Add Java and Python code for cascade classifier and HDR tutorials.
This commit is contained in:
@@ -126,9 +126,9 @@ Result looks like below:
|
||||
Additional Resources
|
||||
--------------------
|
||||
|
||||
-# Video Lecture on [Face Detection and Tracking](http://www.youtube.com/watch?v=WfdYYNamHZ8)
|
||||
2. An interesting interview regarding Face Detection by [Adam
|
||||
Harvey](http://www.makematics.com/research/viola-jones/)
|
||||
-# Video Lecture on [Face Detection and Tracking](https://www.youtube.com/watch?v=WfdYYNamHZ8)
|
||||
-# An interesting interview regarding Face Detection by [Adam
|
||||
Harvey](https://web.archive.org/web/20171204220159/http://www.makematics.com/research/viola-jones/)
|
||||
|
||||
Exercises
|
||||
---------
|
||||
|
||||
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 75 KiB |
@@ -27,7 +27,7 @@ merged, it has to be converted back to 8-bit to view it on usual displays. This
|
||||
tonemapping. Additional complexities arise when objects of the scene or camera move between shots,
|
||||
since images with different exposures should be registered and aligned.
|
||||
|
||||
In this tutorial we show 2 algorithms (Debvec, Robertson) to generate and display HDR image from an
|
||||
In this tutorial we show 2 algorithms (Debevec, Robertson) to generate and display HDR image from an
|
||||
exposure sequence, and demonstrate an alternative approach called exposure fusion (Mertens), that
|
||||
produces low dynamic range image and does not need the exposure times data.
|
||||
Furthermore, we estimate the camera response function (CRF) which is of great value for many computer
|
||||
@@ -65,14 +65,14 @@ exposure_times = np.array([15.0, 2.5, 0.25, 0.0333], dtype=np.float32)
|
||||
### 2. Merge exposures into HDR image
|
||||
|
||||
In this stage we merge the exposure sequence into one HDR image, showing 2 possibilities
|
||||
which we have in OpenCV. The first method is Debvec and the second one is Robertson.
|
||||
which we have in OpenCV. The first method is Debevec and the second one is Robertson.
|
||||
Notice that the HDR image is of type float32, and not uint8, as it contains the
|
||||
full dynamic range of all exposure images.
|
||||
|
||||
@code{.py}
|
||||
# Merge exposures to HDR image
|
||||
merge_debvec = cv.createMergeDebevec()
|
||||
hdr_debvec = merge_debvec.process(img_list, times=exposure_times.copy())
|
||||
merge_debevec = cv.createMergeDebevec()
|
||||
hdr_debevec = merge_debevec.process(img_list, times=exposure_times.copy())
|
||||
merge_robertson = cv.createMergeRobertson()
|
||||
hdr_robertson = merge_robertson.process(img_list, times=exposure_times.copy())
|
||||
@endcode
|
||||
@@ -86,7 +86,7 @@ we will later have to clip the data in order to avoid overflow.
|
||||
@code{.py}
|
||||
# Tonemap HDR image
|
||||
tonemap1 = cv.createTonemapDurand(gamma=2.2)
|
||||
res_debvec = tonemap1.process(hdr_debvec.copy())
|
||||
res_debevec = tonemap1.process(hdr_debevec.copy())
|
||||
tonemap2 = cv.createTonemapDurand(gamma=1.3)
|
||||
res_robertson = tonemap2.process(hdr_robertson.copy())
|
||||
@endcode
|
||||
@@ -111,11 +111,11 @@ integers in the range of [0..255].
|
||||
|
||||
@code{.py}
|
||||
# Convert datatype to 8-bit and save
|
||||
res_debvec_8bit = np.clip(res_debvec*255, 0, 255).astype('uint8')
|
||||
res_debevec_8bit = np.clip(res_debevec*255, 0, 255).astype('uint8')
|
||||
res_robertson_8bit = np.clip(res_robertson*255, 0, 255).astype('uint8')
|
||||
res_mertens_8bit = np.clip(res_mertens*255, 0, 255).astype('uint8')
|
||||
|
||||
cv.imwrite("ldr_debvec.jpg", res_debvec_8bit)
|
||||
cv.imwrite("ldr_debevec.jpg", res_debevec_8bit)
|
||||
cv.imwrite("ldr_robertson.jpg", res_robertson_8bit)
|
||||
cv.imwrite("fusion_mertens.jpg", res_mertens_8bit)
|
||||
@endcode
|
||||
@@ -127,9 +127,9 @@ You can see the different results but consider that each algorithm have addition
|
||||
extra parameters that you should fit to get your desired outcome. Best practice is
|
||||
to try the different methods and see which one performs best for your scene.
|
||||
|
||||
### Debvec:
|
||||
### Debevec:
|
||||
|
||||

|
||||

|
||||
|
||||
### Robertson:
|
||||
|
||||
@@ -150,9 +150,9 @@ function and use it for the HDR merge.
|
||||
|
||||
@code{.py}
|
||||
# Estimate camera response function (CRF)
|
||||
cal_debvec = cv.createCalibrateDebevec()
|
||||
crf_debvec = cal_debvec.process(img_list, times=exposure_times)
|
||||
hdr_debvec = merge_debvec.process(img_list, times=exposure_times.copy(), response=crf_debvec.copy())
|
||||
cal_debevec = cv.createCalibrateDebevec()
|
||||
crf_debevec = cal_debevec.process(img_list, times=exposure_times)
|
||||
hdr_debevec = merge_debevec.process(img_list, times=exposure_times.copy(), response=crf_debevec.copy())
|
||||
cal_robertson = cv.createCalibrateRobertson()
|
||||
crf_robertson = cal_robertson.process(img_list, times=exposure_times)
|
||||
hdr_robertson = merge_robertson.process(img_list, times=exposure_times.copy(), response=crf_robertson.copy())
|
||||
@@ -166,12 +166,12 @@ For this sequence we got the following estimation:
|
||||
Additional Resources
|
||||
--------------------
|
||||
|
||||
1. Paul E Debevec and Jitendra Malik. Recovering high dynamic range radiance maps from photographs. In ACM SIGGRAPH 2008 classes, page 31. ACM, 2008.
|
||||
2. Mark A Robertson, Sean Borman, and Robert L Stevenson. Dynamic range improvement through multiple exposures. In Image Processing, 1999. ICIP 99. Proceedings. 1999 International Conference on, volume 3, pages 159–163. IEEE, 1999.
|
||||
3. Tom Mertens, Jan Kautz, and Frank Van Reeth. Exposure fusion. In Computer Graphics and Applications, 2007. PG'07. 15th Pacific Conference on, pages 382–390. IEEE, 2007.
|
||||
1. Paul E Debevec and Jitendra Malik. Recovering high dynamic range radiance maps from photographs. In ACM SIGGRAPH 2008 classes, page 31. ACM, 2008. @cite DM97
|
||||
2. Mark A Robertson, Sean Borman, and Robert L Stevenson. Dynamic range improvement through multiple exposures. In Image Processing, 1999. ICIP 99. Proceedings. 1999 International Conference on, volume 3, pages 159–163. IEEE, 1999. @cite RB99
|
||||
3. Tom Mertens, Jan Kautz, and Frank Van Reeth. Exposure fusion. In Computer Graphics and Applications, 2007. PG'07. 15th Pacific Conference on, pages 382–390. IEEE, 2007. @cite MK07
|
||||
4. Images from [Wikipedia-HDR](https://en.wikipedia.org/wiki/High-dynamic-range_imaging)
|
||||
|
||||
Exercises
|
||||
---------
|
||||
1. Try all tonemap algorithms: [Drago](http://docs.opencv.org/master/da/d53/classcv_1_1TonemapDrago.html), [Durand](http://docs.opencv.org/master/da/d3d/classcv_1_1TonemapDurand.html), [Mantiuk](http://docs.opencv.org/master/de/d76/classcv_1_1TonemapMantiuk.html) and [Reinhard](http://docs.opencv.org/master/d0/dec/classcv_1_1TonemapReinhard.html).
|
||||
2. Try changing the parameters in the HDR calibration and tonemap methods.
|
||||
1. Try all tonemap algorithms: cv::TonemapDrago, cv::TonemapDurand, cv::TonemapMantiuk and cv::TonemapReinhard
|
||||
2. Try changing the parameters in the HDR calibration and tonemap methods.
|
||||
|
||||
@@ -17,9 +17,23 @@ Theory
|
||||
Code
|
||||
----
|
||||
|
||||
@add_toggle_cpp
|
||||
This tutorial code's is shown lines below. You can also download it from
|
||||
[here](https://github.com/opencv/opencv/tree/3.4/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp)
|
||||
@include samples/cpp/tutorial_code/objectDetection/objectDetection.cpp
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
This tutorial code's is shown lines below. You can also download it from
|
||||
[here](https://github.com/opencv/opencv/tree/3.4/samples/java/tutorial_code/objectDetection/cascade_classifier/ObjectDetectionDemo.java)
|
||||
@include samples/java/tutorial_code/objectDetection/cascade_classifier/ObjectDetectionDemo.java
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
This tutorial code's is shown lines below. You can also download it from
|
||||
[here](https://github.com/opencv/opencv/tree/3.4/samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py)
|
||||
@include samples/python/tutorial_code/objectDetection/cascade_classifier/objectDetection.py
|
||||
@end_toggle
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
@@ -40,3 +54,13 @@ Result
|
||||
detection. For the eyes we keep using the file used in the tutorial.
|
||||
|
||||

|
||||
|
||||
Additional Resources
|
||||
--------------------
|
||||
|
||||
-# Paul Viola and Michael J. Jones. Robust real-time face detection. International Journal of Computer Vision, 57(2):137–154, 2004. @cite Viola04
|
||||
-# Rainer Lienhart and Jochen Maydt. An extended set of haar-like features for rapid object detection. In Image Processing. 2002. Proceedings. 2002 International Conference on, volume 1, pages I–900. IEEE, 2002. @cite Lienhart02
|
||||
-# Video Lecture on [Face Detection and Tracking](https://www.youtube.com/watch?v=WfdYYNamHZ8)
|
||||
-# An interesting interview regarding Face Detection by [Adam
|
||||
Harvey](https://web.archive.org/web/20171204220159/http://www.makematics.com/research/viola-jones/)
|
||||
-# [OpenCV Face Detection: Visualized](https://vimeo.com/12774628) on Vimeo by Adam Harvey
|
||||
|
||||
@@ -5,6 +5,8 @@ Ever wondered how your digital camera detects peoples and faces? Look here to fi
|
||||
|
||||
- @subpage tutorial_cascade_classifier
|
||||
|
||||
*Languages:* C++, Java, Python
|
||||
|
||||
*Compatibility:* \> OpenCV 2.0
|
||||
|
||||
*Author:* Ana Huamán
|
||||
|
||||
@@ -31,21 +31,51 @@ Exposure sequence
|
||||
Source Code
|
||||
-----------
|
||||
|
||||
@include cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp
|
||||
@add_toggle_cpp
|
||||
This tutorial code's is shown lines below. You can also download it from
|
||||
[here](https://github.com/opencv/opencv/tree/3.4/samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp)
|
||||
@include samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
This tutorial code's is shown lines below. You can also download it from
|
||||
[here](https://github.com/opencv/opencv/tree/3.4/samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java)
|
||||
@include samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
This tutorial code's is shown lines below. You can also download it from
|
||||
[here](https://github.com/opencv/opencv/tree/3.4/samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py)
|
||||
@include samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py
|
||||
@end_toggle
|
||||
|
||||
Sample images
|
||||
-------------
|
||||
|
||||
Data directory that contains images, exposure times and `list.txt` file can be downloaded from
|
||||
[here](https://github.com/opencv/opencv_extra/tree/3.4/testdata/cv/hdr/exposures).
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
-# **Load images and exposure times**
|
||||
@code{.cpp}
|
||||
vector<Mat> images;
|
||||
vector<float> times;
|
||||
loadExposureSeq(argv[1], images, times);
|
||||
@endcode
|
||||
Firstly we load input images and exposure times from user-defined folder. The folder should
|
||||
contain images and *list.txt* - file that contains file names and inverse exposure times.
|
||||
- **Load images and exposure times**
|
||||
|
||||
For our image sequence the list is following:
|
||||
@add_toggle_cpp
|
||||
@snippet samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp Load images and exposure times
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
@snippet samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java Load images and exposure times
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
@snippet samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py Load images and exposure times
|
||||
@end_toggle
|
||||
|
||||
Firstly we load input images and exposure times from user-defined folder. The folder should
|
||||
contain images and *list.txt* - file that contains file names and inverse exposure times.
|
||||
|
||||
For our image sequence the list is following:
|
||||
@code{.none}
|
||||
memorial00.png 0.03125
|
||||
memorial01.png 0.0625
|
||||
@@ -53,53 +83,96 @@ Explanation
|
||||
memorial15.png 1024
|
||||
@endcode
|
||||
|
||||
-# **Estimate camera response**
|
||||
@code{.cpp}
|
||||
Mat response;
|
||||
Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
|
||||
calibrate->process(images, response, times);
|
||||
@endcode
|
||||
It is necessary to know camera response function (CRF) for a lot of HDR construction algorithms.
|
||||
We use one of the calibration algorithms to estimate inverse CRF for all 256 pixel values.
|
||||
- **Estimate camera response**
|
||||
|
||||
@add_toggle_cpp
|
||||
@snippet samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp Estimate camera response
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
@snippet samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java Estimate camera response
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
@snippet samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py Estimate camera response
|
||||
@end_toggle
|
||||
|
||||
It is necessary to know camera response function (CRF) for a lot of HDR construction algorithms.
|
||||
We use one of the calibration algorithms to estimate inverse CRF for all 256 pixel values.
|
||||
|
||||
- **Make HDR image**
|
||||
|
||||
@add_toggle_cpp
|
||||
@snippet samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp Make HDR image
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
@snippet samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java Make HDR image
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
@snippet samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py Make HDR image
|
||||
@end_toggle
|
||||
|
||||
-# **Make HDR image**
|
||||
@code{.cpp}
|
||||
Mat hdr;
|
||||
Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
|
||||
merge_debevec->process(images, hdr, times, response);
|
||||
@endcode
|
||||
We use Debevec's weighting scheme to construct HDR image using response calculated in the previous
|
||||
item.
|
||||
|
||||
-# **Tonemap HDR image**
|
||||
@code{.cpp}
|
||||
Mat ldr;
|
||||
Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);
|
||||
tonemap->process(hdr, ldr);
|
||||
@endcode
|
||||
Since we want to see our results on common LDR display we have to map our HDR image to 8-bit range
|
||||
preserving most details. It is the main goal of tonemapping methods. We use tonemapper with
|
||||
bilateral filtering and set 2.2 as the value for gamma correction.
|
||||
- **Tonemap HDR image**
|
||||
|
||||
-# **Perform exposure fusion**
|
||||
@code{.cpp}
|
||||
Mat fusion;
|
||||
Ptr<MergeMertens> merge_mertens = createMergeMertens();
|
||||
merge_mertens->process(images, fusion);
|
||||
@endcode
|
||||
There is an alternative way to merge our exposures in case when we don't need HDR image. This
|
||||
process is called exposure fusion and produces LDR image that doesn't require gamma correction. It
|
||||
also doesn't use exposure values of the photographs.
|
||||
@add_toggle_cpp
|
||||
@snippet samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp Tonemap HDR image
|
||||
@end_toggle
|
||||
|
||||
-# **Write results**
|
||||
@code{.cpp}
|
||||
imwrite("fusion.png", fusion * 255);
|
||||
imwrite("ldr.png", ldr * 255);
|
||||
imwrite("hdr.hdr", hdr);
|
||||
@endcode
|
||||
Now it's time to look at the results. Note that HDR image can't be stored in one of common image
|
||||
formats, so we save it to Radiance image (.hdr). Also all HDR imaging functions return results in
|
||||
[0, 1] range so we should multiply result by 255.
|
||||
@add_toggle_java
|
||||
@snippet samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java Tonemap HDR image
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
@snippet samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py Tonemap HDR image
|
||||
@end_toggle
|
||||
|
||||
Since we want to see our results on common LDR display we have to map our HDR image to 8-bit range
|
||||
preserving most details. It is the main goal of tonemapping methods. We use tonemapper with
|
||||
bilateral filtering and set 2.2 as the value for gamma correction.
|
||||
|
||||
- **Perform exposure fusion**
|
||||
|
||||
@add_toggle_cpp
|
||||
@snippet samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp Perform exposure fusion
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
@snippet samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java Perform exposure fusion
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
@snippet samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py Perform exposure fusion
|
||||
@end_toggle
|
||||
|
||||
There is an alternative way to merge our exposures in case when we don't need HDR image. This
|
||||
process is called exposure fusion and produces LDR image that doesn't require gamma correction. It
|
||||
also doesn't use exposure values of the photographs.
|
||||
|
||||
- **Write results**
|
||||
|
||||
@add_toggle_cpp
|
||||
@snippet samples/cpp/tutorial_code/photo/hdr_imaging/hdr_imaging.cpp Write results
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_java
|
||||
@snippet samples/java/tutorial_code/photo/hdr_imaging/HDRImagingDemo.java Write results
|
||||
@end_toggle
|
||||
|
||||
@add_toggle_python
|
||||
@snippet samples/python/tutorial_code/photo/hdr_imaging/hdr_imaging.py Write results
|
||||
@end_toggle
|
||||
|
||||
Now it's time to look at the results. Note that HDR image can't be stored in one of common image
|
||||
formats, so we save it to Radiance image (.hdr). Also all HDR imaging functions return results in
|
||||
[0, 1] range so we should multiply result by 255.
|
||||
|
||||
You can try other tonemap algorithms: cv::TonemapDrago, cv::TonemapDurand, cv::TonemapMantiuk and cv::TonemapReinhard
|
||||
You can also adjust the parameters in the HDR calibration and tonemap methods for your own photos.
|
||||
|
||||
Results
|
||||
-------
|
||||
@@ -111,3 +184,12 @@ Results
|
||||
### Exposure fusion
|
||||
|
||||

|
||||
|
||||
Additional Resources
|
||||
--------------------
|
||||
|
||||
1. Paul E Debevec and Jitendra Malik. Recovering high dynamic range radiance maps from photographs. In ACM SIGGRAPH 2008 classes, page 31. ACM, 2008. @cite DM97
|
||||
2. Mark A Robertson, Sean Borman, and Robert L Stevenson. Dynamic range improvement through multiple exposures. In Image Processing, 1999. ICIP 99. Proceedings. 1999 International Conference on, volume 3, pages 159–163. IEEE, 1999. @cite RB99
|
||||
3. Tom Mertens, Jan Kautz, and Frank Van Reeth. Exposure fusion. In Computer Graphics and Applications, 2007. PG'07. 15th Pacific Conference on, pages 382–390. IEEE, 2007. @cite MK07
|
||||
4. [Wikipedia-HDR](https://en.wikipedia.org/wiki/High-dynamic-range_imaging)
|
||||
5. [Recovering High Dynamic Range Radiance Maps from Photographs (webpage)](http://www.pauldebevec.com/Research/HDR/)
|
||||
|
||||
@@ -5,6 +5,8 @@ Use OpenCV for advanced photo processing.
|
||||
|
||||
- @subpage tutorial_hdr_imaging
|
||||
|
||||
*Languages:* C++, Java, Python
|
||||
|
||||
*Compatibility:* \> OpenCV 3.0
|
||||
|
||||
*Author:* Fedor Morozov
|
||||
|
||||
Reference in New Issue
Block a user