Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

OpenCV 3D module rendering function PR#24065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
nickyu-zhu wants to merge1,762 commits intoopencv:5.xfromnickyu-zhu:Ningyu-dev

Conversation

@nickyu-zhu
Copy link

Pull Request for GSoC 2023 Project5 - Simple Triangle Rendering

This is a pull request for OpenCV 3d module in 5.x branch, which is the work of GSoC 2023 project 5. The changes are demonstrated down below.

  1. Create rendering.cpp and rendering.hpp files in opencv/modules/src folder, which can render the input triangles through the triangleRastrize() function. This new function can now perform depth and color rendering successfully
  2. Create test_rendering.cpp file in the opencv/modules/test folder, which test the triangleRastrize() function in 4 different ways, (including empty set, constant color rendering, interpolated color rendering and clipping test rendering)
  3. Add three new files in opencv/sample/opengl folder. The names are opengl_clipping_sample.cpp, opengl_color_sample.cpp and opengl_depth._sample.cpp. These files are set to be the OpenGL ground truth samples for the rendering image.

Harveyand others added30 commitsOctober 21, 2021 18:13
* bmp specified BI_BITFIELDS should take care RGBA bit mask* support xrgb bmp file
add test case for "tf/reduce_sum"* fix output dimension of reduce_sum* add test case and fix bug* add more cases* style:change files name* fix a little bug
Add regression test for QRcode encoding and decodingCo-authored-by: APrigarina <ann73617@gmail.com>
Signed-off-by: Crayon-new <1349159541@qq.com>
Onnx conformance tests* Add ONNX conformance tests* dnn(onnx): make conformance stubs a part of repositoryCo-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
Signed-off-by: Crayon-new <1349159541@qq.com>
Copy link
Contributor

@savuorsavuor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is a good progress. There's a couple of things to fix:

  1. My comments
  2. Broken CI tests

*/
CV_EXPORTS_WvoidsaveMesh(const String &filename, InputArray vertices, InputArray normals, InputArrayOfArrays indices);

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This comment does not render to docs.
You can always check the generated documentation for the PRhere (Builders -> default -> PR number -> Docs -> Upload docs -> Preview).

@@ -0,0 +1 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We don't need empty files, please remove

{
if (debugLevel >0)
{
Mat groundTruth =imread("../../../opencv_extra/opencv_extra/testdata/rendering/example_image_depth_1.png");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This file path will work on your machine only.
We have a special function to obtain a path:

// The file path is OPENCV_TEST_DATA_PATH + "/rendering/example_image_depth_1.png"std::string dataPath = cvtest::TS::ptr()->get_data_path() + "/rendering/example_image_depth_1.png";

The test executables should be run with env variableOPENCV_TEST_DATA_PATH set totestdata folder

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

findDataFile() should be used.


std::vector<Vec3f> verticesVector = vertices.getMat();
std::vector<Vec3f> indicesVector = indices.getMat();
std::vector<Vec3f> colorsVector = colors.getMat();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should allow an empty vertex colors array. In that case all the triangles will be drawn by the same color (let it be full white).

**/
CV_EXPORTSvoidtriangleRasterize(InputArray vertices, InputArray indices,
InputArray colors, InputArray cameraMatrix,int width,int height,bool shadingMode,
OutputArray depth_buf, OutputArray color_buf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

OK, the thing happened tocameraMatrix is not what I was talking about. It should be changed:

  • The way of passing camera pose by lookAt, position and up vector is not an OpenCV-style, we use camera pose matrix for that (in your code this is calledlookAtMatrix
  • The intrinsic camera parameters are also passed in different way, by 3x3 intrinsic matrix
    I'll rewrite the doc string, and you are to change the function signature according to it.
Renders a set of triangles on a depth and/or RGB image. The output images are not cleared before the rendering and can be used for masking or with pre-filled Z-buffer.Triangles can be flat-shaded or have interpolated colors between vertices. In flat-shaded mode a color of 1st triangle vertex is used.If no colors are given, the triangles are drawn in white (1.0, 1.0, 1.0).@param vertices vertices coordinates array. Should contain values of CV_32FC3 type or a compatible one (e.g. cv::Vec3f, etc.)@param indices triangle vertices index array, 3 per triangle. Each index indicates a vertex in a vertices array. Should contain CV_32SC3 values@param colors per-vertex colors of CV_32FC3 type, can be empty.@param cameraPose a 4x3 or 4x4 float matrix containing camera pose@param fovY field of view in vertical direction, given in degrees@param zNear minimum Z value to render, everything closer is clipped@param zFar maximum Z value to render, everything farther is clipped@param width Frame width@param height Frame height@param useFlatShading Enables or disables flat shading *@param depthBuf a width x height array of floats containing resulting Z buffer. Reused if not empty. Created and filled by zFar values if a user-provided array is empty. To disable Z buffer output, pass cv::noArray() here.*@param colorBuf a width x height array of CV_32FC3 representing the final rendered image. Reused if not empty. Created and filled by zeroes if a user-provided array is empty. To disable color output, pass cv::noArray() here.
CV_EXPORTS  void triangleRasterize(InputArray vertices, InputArray indices,    InputArray colors, InputArray cameraPose, float fovY, float zNear, float zFar,int width, int height, bool useFlatShading,    OutputArray depthBuf=noArray(), OutputArray colorBuf=noArray());

Vec3f position = camera.row(0);
Vec3f lookat = camera.row(1);
Vec3f upVector = camera.row(2);
float fovy = camera.at<float>(3,0), zNear = camera.at<float>(3,1), zFar = camera.at<float>(3,2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Please change this according to new function signature

Matx44f mvpMatrix = perspectMatrix * lookAtMatrix;

Mat depth_buf_mat = depth_buf.getMat();
Mat color_buf_mat = color_buf.getMat();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

  • Both depthBuf and colorBufOutputArray arguments should be checked for size, type,empty() andneeded()
  • If they are empty, they should be created with givenwidth andheight
  • If color buffer is not needed then the color rendering should be disabled
  • If depth buffer is not needed then we still need it during rendering, just don't pass it outside

returnVec3f(a[0] / length, a[1] / length, a[2] / length);
}

Matx44flookAtMatrixCal(const Vec3f& position,const Vec3f& lookat,const Vec3f& upVector)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As I said earlier, this function makes more sense in test/perf files rather than here.
As an option, we can expose it to public interface

if (ACcrossAB.dot(ACcrossAP) >=0 && ABcrossAC.dot(ABcrossAP) >=0)
{
float beta =norm(ACcrossAP) /norm(ACcrossAB);
float gamma =norm(ABcrossAP) /norm(ABcrossAC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

norm(ACcrossAB) == norm(ABcrossAC), this can be optimized

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If the triangle is degenerate or close to, we'll get division by zero problem, this should be avoided

if (ACcrossAB.dot(ACcrossAP) >=0 && ABcrossAC.dot(ABcrossAP) >=0)
{
float beta =norm(ACcrossAP) /norm(ACcrossAB);
float gamma =norm(ABcrossAP) /norm(ABcrossAC);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The same about div by zero

fengyuentauand others added4 commitsSeptember 6, 2023 17:03
VIT track(gsoc realtime object tracking model)opencv#1088add an onnx model for opencv vttrack PRopencv#24201
* add converted conformance gemm tests* update to modern googlenet with new outputs* correct filename* replace model link with the one from org gdrive* drop googlenet 2023
#include<windows.h>
#defineWIN32_LEAN_AND_MEAN1
#defineNOMINMAX1
#include<windows.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

avoid unnecessary changes

@@ -0,0 +1,212 @@
#include"precomp.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Missing license header

Comment on lines 3 to 8
namespacecv {

structTriangle
{
Vec4f vertices[3];
Vec3f color[3];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

avoid indentation in namespaces (all files)

{
if (debugLevel >0)
{
Mat groundTruth =imread("../../../opencv_extra/opencv_extra/testdata/rendering/example_image_depth_1.png");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

findDataFile() should be used.

structDrawData
{
ogl::Arrays arr;
ogl::Buffer indices;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Don't use tabs in source code.
Follow OpenCV coding style guidelines.

Abdurrahheemand others added18 commitsSeptember 22, 2023 13:05
* add expand conformance tests* fix clip-vit-base-head model and its output
Model and test data for the fix of shared const inputs
dnn: download_models script improvementsopencv#1084Added new features:* Use argument parser and new arguments:  * `--cache` directory will be tried before downloading from internet  * `--dst` change destination directory  * `--list` list all model names  * `--cleanup` remove all `tar.gz` files afterwards* Add hierarchy to model structure, now there are regular models which can be downloaded directly and archived models which should be downloaded and then required files will be extracted. Archived files will be checked for existence before downloading whole archive - it allows to populate them from cache and avoid storing archives on disk.* Filters are now case-insensitive and use _contains_ rule for matching, multiple filters can be used in the command line, results will be united.* GDrive object simplified to separate method - allows to reduce repeated download code. Better solution would be to extract all download-store-verify functionality to separate class(es), but I decided to postpone this step for the future improvements.* Use `pathlib.Path` for most paths.I have doubts regarding filter arguments: should we keep them positional arguments or change to keyword arguments (e.g. `--filter`)?Examples:```.sh# Populate cache and remove archives afterwards (~4Gb)./download_models.py --dst /data/dnn --cleanup# Download models to the specified folder using cache./download_models.py --cache /data/dnn --dst $HOME/opencv_extra/testdata/dnn# List all models having face in their name./download_models.py --list face```
Updated performance test sanity data for PR opencv/opencv:24333.
Merge withopencv#24386Also noted that random seed is added in this pr, so previous data is regenerated to keep consistency.
@savuor
Copy link
Contributor

savuor commentedOct 27, 2023
edited
Loading

Reopened as#24459

@savuorsavuor mentioned this pull requestOct 27, 2023
6 tasks
asmorkalov pushed a commit that referenced this pull requestFeb 19, 2024
Triangle rasterization function#24459#24065 reopened since the previous one was automatically closed after rebaseConnected PR with ground truth data: [#1113@extra](opencv/opencv_extra#1113)### Pull Request Readiness ChecklistSee details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request- [x] I agree to contribute to the project under Apache 2 License.- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV- [x] The PR is proposed to the proper branch- [x] There is a reference to the original bug report and related work- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable      Patch to opencv_extra has the same branch name.- [x] The feature is well documented and sample code can be built with the project CMake
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@asmorkalovasmorkalovasmorkalov left review comments

@opencv-alalekopencv-alalekopencv-alalek left review comments

@savuorsavuorsavuor requested changes

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

20 participants

@nickyu-zhu@savuor@asmorkalov@opencv-alalek@alalek@Harvey-Huang@APrigarina@Crayon-new@ZhengQiushi@rogday@cqn2219076254@sturkmen72@stal12@zihaomu@fengyuentau@chacha21@opencv-pushbot@ibvfteh@Kumataro@WanliZhong

[8]ページ先頭

©2009-2025 Movatter.jp