
\u8f6e\u76d8\u6e38\u620f\u3002\u56fa\u5b9a\u7684\u89d2\u5ea6\u5f55\u5236\u6709 10 \u4e07\u6b21\u7ed3\u679c\u3002\n\u6839\u636e\u8fd9\u4e9b\u5b8c\u6574\u6570\u636e\uff0c\u80fd\u9884\u6d4b\u51fa\u767d\u7403\u662f\u843d\u5728\u5de6\u8fb9\u8fd8\u662f\u53f3\u8fb9\u5417\uff1f\n\u6211\u67e5\u9605\u4e86\u4e00\u4e9b\u8d44\u6599 \u56fd\u5916\u6709\u5f88\u591a\u4eba\u505a\u8fc7\u8fd9\u4e9b\u7814\u7a76\u3002\u7406\u8bba\u4e0a\u662f\u53ef\u884c\u7684\u3002
\n\u76f8\u5173\u8d44\u6599\n\u4f7f\u7528 OpenCV \u4e8c\u8fdb\u5236\u63a9\u7801\u68c0\u6d4b\u8f6e\u76d8\u548c\u7403\u901f\nhttps://www.linkedin.com/pulse/roulette-wheel-ball-speed-detection-opencv-binary-mask-muhammad-anas-nqy4f
\nhttps://www.youtube.com/watch?v=bpy933SQ6Q0\nhttps://www.youtube.com/watch?v=kibZDD_I9HY\nhttps://www.youtube.com/watch?v=HaMlKvNqCVs\nhttps://www.spinsight.ai/
\n" }, { "author": { "url": "member/kxg3030", "name": "kxg3030", "avatar": "https://cdn.v2ex.com/avatar/cb4c/e983/689061_large.png?m=1715074476" }, "url": "t/1072243", "date_modified": "2024-09-12T13:38:22+00:00", "content_html": "\u5728\u4f7f\u7528 pyqt+opencv \u5904\u7406\u52a8\u6001\u56fe\u50cf\u878d\u5408\u7136\u540e\u505a\u8def\u5f84\u89c4\u5212\uff0c\u4f46\u56fe\u50cf\u7279\u5f81\u878d\u5408\u7684\u65f6\u5019\uff0c\u5df2\u7ecf\u878d\u5408\u7684\u90e8\u5206\u4f1a\u8d8a\u6765\u8d8a\u6a21\u7cca\uff0c\u989c\u8272\u4e5f\u4f1a\u53d8\u6df1\uff0c\u6709\u6ca1\u4ec0\u4e48\u529e\u6cd5\u53ef\u4ee5\u89e3\u51b3\u7684\n

\u6211\u6709\u4e00\u53f0\u56fa\u5b9a\u5728\u4e91\u53f0\u4e0a\u7684\u76f8\u673a\uff0c\u6211\u60f3\u8981\u77e5\u9053\u8fd9\u4e2a\u76f8\u673a\u76f8\u5bf9\u5b89\u88c5\u5e73\u53f0\u7684\u65cb\u8f6c\u548c\u5e73\u79fb\u91cf\u3002\u5176\u4e2d\u4e91\u53f0\u662f\u56fa\u5b9a\u4e0d\u52a8\u7684\uff0c\u53ea\u6709 pitch \u3001yaw \u3001\u548c roll \u8f74\u7684\u8fd0\u52a8\u3002\u67e5\u4e86\u4e00\u4e0b\u5e94\u8be5\u662f\u7528\u8fd9\u4e2a\u51fd\u6570\uff1a
\nvoid calibrateHandEye(\n InputArrayOfArrays R_gripper2base, // \u4e91\u53f0 p y r \u89d2\u5ea6\u8f6c\u6362\u51fa\u6765\u7684\u65cb\u8f6c\u77e9\u9635\n InputArrayOfArrays t_gripper2base, // \u8f93\u5165\u7684\u662f 0 \uff0c\u56e0\u4e3a\u6ca1\u6709\u4efb\u4f55\u79fb\u52a8\uff08\u5e76\u4e14\u60f3\u7528\u4e91\u53f0\u5e73\u53f0\u5f53\u4e16\u754c\u5750\u6807\u4e2d\u5fc3\u70b9\uff09\n InputArrayOfArrays R_target2cam, // calibrateCamera \u8f93\u51fa\u7684 rvec\n InputArrayOfArrays t_target2cam, // calibrateCamera \u8f93\u51fa\u7684 tvec\n OutputArray R_cam2gripper, \n OutputArray t_cam2gripper, \n HandEyeCalibrationMethod method = CALIB_HAND_EYE_TSAI)\n\n\u6211\u73b0\u5728\u662f\u8fd9\u6837\u505a\u7684\uff1a
\n\u4f46\u662f\u7ed3\u679c\u548c\u5b9e\u9645\u76f8\u5dee\u5de8\u5927\u3002\u56e0\u6b64\u60f3\u6765 V \u7ad9\u770b\u770b\u6709\u6ca1\u6709\u4eba\u6709\u8fc7\u8fd9\u65b9\u9762\u7ecf\u9a8c\uff0c\u80fd\u770b\u51fa\u6211\u7684\u6b65\u9aa4\u91cc\u53ef\u80fd\u6709\u4ec0\u4e48\u95ee\u9898\u2026\u2026\u5148\u5728\u8fd9\u91cc\u8c22\u8fc7\u5404\u4f4d\u4e86\uff01
\n\u6211\u4e2a\u4eba\u611f\u89c9\u6bd4\u8f83\u5bb9\u6613\u51fa\u95ee\u9898\u7684\u5730\u65b9\u662f\u7b2c\u4e09\u6b65\u7684\u8f6c\u6362\uff0c\u6211\u662f\u8fd9\u6837\u5199\u7684\uff1a
\n Eigen::Quaternionf euler2quaternionf(const float z, const float y, const float x)\n {\n const float cos_z = cos(z * 0.5f), sin_z = sin(z * 0.5f),\n cos_y = cos(y * 0.5f), sin_y = sin(y * 0.5f),\n cos_x = cos(x * 0.5f), sin_x = sin(x * 0.5f);\n\n Eigen::Quaternionf quaternion(\n cos_z * cos_y * cos_x + sin_z * sin_y * sin_x,\n cos_z * cos_y * sin_x - sin_z * sin_y * cos_x,\n sin_z * cos_y * sin_x + cos_z * sin_y * cos_x,\n sin_z * cos_y * cos_x - cos_z * sin_y * sin_x\n );\n\n return quaternion;\n }\n\n\n\u5148\u8f6c\u6362\u4e3a\u56db\u5143\u6570\uff0c\u518d\u6c42\u65cb\u8f6c\u77e9\u9635\uff08\u7528 Eigen \u81ea\u5e26\u7684\u65b9\u6cd5\uff09\u3002
\n" }, { "author": { "url": "member/norkki", "name": "norkki", "avatar": "https://cdn.v2ex.com/avatar/7002/36cf/586480_large.png?m=1718509459" }, "url": "t/1049921", "title": "[\u6c42\u52a9]C++ \u7528\u5230 OpenCV \u5e93 \u600e\u4e48\u9759\u6001\u7f16\u8bd1\u5462?", "id": "t/1049921", "date_published": "2024-06-16T03:57:02+00:00", "content_html": "\u6d4b\u8bd5\u4ee3\u7801\u5982\u4e0b:
\n\n#include <opencv2/opencv.hpp>\n#include <iostream>\n\nint main(int argc, char** argv) {\n cv::Mat image = cv::imread(\"image.jpg\");\n if (image.empty()) {\n std::cout << \"Error loading image!\" << std::endl;\n return -1;\n }\n // cv::imshow(\"Image\", image);\n std::cout << \"size: \"\n << image.cols << \"x\" << image.rows\n << std::endl;\n return 0;\n}\n\nc++ -o cv-test cv-test.cc -I/usr/local/opencv/include/opencv4/ -L/usr/local/opencv/lib64/ -lopencv_core -lopencv_imgcodecs
\u6b63\u5e38\u7f16\u8bd1
\n\u52a0\u4e0a -static\u5c1d\u8bd5\u9759\u6001\u7f16\u8bd1 (opencv \u662f\u6709\u7f16\u8bd1\u9759\u6001\u5e93\u7684/usr/local/opencv/lib64/libopencv_core.a)
c++ -o cv-test cv-test.cc -I/usr/local/opencv/include/opencv4/ -L/usr/local/opencv/lib64/ -lopencv_core -lopencv_imgcodecs -static
\u62a5\u9519:
\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(opencl_core.cpp.o): in function `opencl_check_fn(int)':\n/home/nick/github/opencv/modules/core/src/opencl/runtime/opencl_core.cpp:166: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwiImage::Release()':\n/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_image.hpp:945: undefined reference to `iwAtomic_AddInt'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwiImage::~IwiImage()':\n/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_image.hpp:813: undefined reference to `iwAtomic_AddInt'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwiImage::Release()':\n/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_image.hpp:957: undefined reference to `iwiImage_Release'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp::IwException::IwException(int)':\n/home/nick/github/opencv/build/3rdparty/ippicv/ippicv_lnx/iw/include/iw++/iw_core.hpp:133: undefined reference to `iwGetStatusString'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `cv::transpose(cv::_InputArray const&, cv::_OutputArray const&)':\n/home/nick/github/opencv/modules/core/src/matrix_transform.cpp:228: undefined reference to `ippicviTranspose_32f_C4R'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_core.a(matrix_transform.cpp.o): in function `ipp_transpose':\n/home/nick/github/opencv/modules/core/src/matrix_transform.cpp:228: undefined reference to `ippicviTranspose_32s_C3R'\n/usr/bin/ld: /home/nick/github/opencv/modules/core/src/matrix_transform.cpp:228: undefined reference to `ippicviTranspose_16s_C3R'\n\n...\n\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<unsigned char*, void (*)(void*), std::allocator<void>, void>(unsigned char*, void (*)(void*), std::allocator<void>)':\n/usr/include/c++/13/bits/shared_ptr_base.h:958: undefined reference to `WebPFree'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `cv::WebPEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)':\n/home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:286: undefined reference to `WebPEncodeLosslessBGRA'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `std::_Sp_ebo_helper<0, void (*)(void*), false>::_Sp_ebo_helper(void (*&&)(void*))':\n/usr/include/c++/13/bits/shared_ptr_base.h:482: undefined reference to `WebPFree'\n/usr/bin/ld: /usr/local/opencv/lib64//libopencv_imgcodecs.a(grfmt_webp.cpp.o): in function `cv::WebPEncoder::write(cv::Mat const&, std::vector<int, std::allocator<int> > const&)':\n/home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:271: undefined reference to `cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)'\n/usr/bin/ld: /home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:293: undefined reference to `WebPEncodeBGR'\n/usr/bin/ld: /home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:297: undefined reference to `WebPEncodeBGRA'\n/usr/bin/ld: /home/nick/github/opencv/modules/imgcodecs/src/grfmt_webp.cpp:282: undefined reference to `WebPEncodeLosslessBGR'\n/usr/bin/ld: cv-test: hidden symbol `opj_stream_destroy' isn't defined\n/usr/bin/ld: final link failed: bad value\ncollect2: error: ld returned 1 exit status\n\n\n\u8bf7\u95ee\u5927\u4f6c\u6709\u6ca1\u6709\u529e\u6cd5\u9759\u6001\u7f16\u8bd1
\n" }, { "author": { "url": "member/anai1943", "name": "anai1943", "avatar": "https://cdn.v2ex.com/gravatar/960467b15541a723f059ecc949bf1856?s=73&d=retro" }, "url": "t/1046551", "title": "opencv \u53bb\u9664\u89c6\u9891\u4e2d\u79fb\u52a8\u7684\u6587\u5b57", "id": "t/1046551", "date_published": "2024-06-04T01:18:43+00:00", "content_html": "\u5982\u56fe\u6240\u793a\uff0c\u89c6\u9891\u753b\u9762\u4e2d\u4f1a\u51fa\u73b0\u4ece\u5de6\u5230\u53f3\u6216\u8005\u4ece\u4e0b\u5230\u4e0a\u79fb\u52a8\u7684\u6587\u5b57\uff0c\u7531\u4e8e\u672c\u673a\u6ca1\u6709 N \u5361\uff08\u5f88\u591a AI \u53bb\u9664\u7684\u5f00\u6e90\u9879\u76ee\u9700\u8981 N \u5361\u652f\u6301\uff09\uff0c\u6253\u7b97\u5148\u7528 python + opencv \u6765\u8bd5\u8bd5\uff0c\u5e0c\u671b\u53bb\u9664\u79fb\u52a8\u6587\u5b57\u540e\uff0c\u80cc\u666f\u753b\u9762\u5c3d\u91cf\u4e0d\u7834\u574f\u3002
\n\u76ee\u524d\u7684\u601d\u8def\u662f\u5148\u6846\u9009\u51fa\u6765\u6587\u5b57\u533a\u57df\u4f5c\u4e3a\u6a21\u677f\uff0c\u518d\u95f4\u9694\u51e0\u79d2\u627e\u4e00\u5e27\u505a\u6a21\u677f\u5339\u914d\uff0c\u5982\u679c\u5339\u914d\u4e0a\uff0c\u7528\u76f8\u90bb\u7684\u672a\u51fa\u73b0\u6587\u5b57\u7684\u5e27\u7684\u753b\u9762\u6765\u66ff\u6362\u6709\u6587\u5b57\u5185\u5bb9\u7684\u5e27\uff0c\u5982\u679c\u51fa\u73b0\u79fb\u52a8\u6587\u5b57\u7684\u753b\u9762\u4e5f\u6709\u5176\u5b83\u79fb\u52a8\u7684\u5bf9\u8c61\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5c31\u4e0d\u884c\u4e86\uff0c\u8fd8\u6709\u5176\u5b83\u597d\u7684\u601d\u8def\u4e48\uff0c\u611f\u8c22\uff01
\n
\n\u793a\u610f\u56fe 1
\n\u793a\u610f\u56fe 2
def capture_photo():\n# \u6253\u5f00\u6444\u50cf\u5934\ncap = cv2.VideoCapture(0)
\n# \u68c0\u67e5\u6444\u50cf\u5934\u662f\u5426\u6253\u5f00\u6210\u529f\nif not cap.isOpened():\n raise Exception(\"Failed to open camera\")\n# \u56fe\u7247\u4e3a\u9ed1\uff0c\u5fc5\u987b sleep \u4e00\u4e0b\uff01\uff01\uff01\nsleep(0.1)\n# \u8bfb\u53d6\u4e00\u5e27\u56fe\u50cf\nret, frame = cap.read()\n\n# \u68c0\u67e5\u56fe\u50cf\u662f\u5426\u8bfb\u53d6\u6210\u529f\nif not ret:\n raise Exception(\"Failed to capture frame\")\n\n# \u91ca\u653e\u6444\u50cf\u5934\ncap.release()\n\n# \u4fdd\u5b58\u56fe\u50cf\u5230\u5f53\u524d\u76ee\u5f55\ncv2.imwrite(\"captured_photo.jpg\", frame)\n\nreturn \"Photo captured successfully\"\n\n", "date_published": "2024-04-15T08:44:35+00:00", "title": "Opencv \u9047\u5230\u4e00\u4e2a\u5f88\u5947\u602a\u7684\u95ee\u9898\uff0c mac \u4e0a\u83b7\u53d6\u6444\u50cf\u5934\u56fe\u7247\uff0c\u5fc5\u987b\u9700\u8981 sleep \u4e00\u4e0b\uff0c 0.1 \u90fd\u53ef\u4ee5\uff0c\u4f46\u662f\u4e0d\u7ed9\u5c31\u662f\u9ed1\u56fe\uff0c\u4ee3\u7801\u5982\u4e0b\uff0c\u6709\u6ca1\u6709\u5927\u4f6c\u6307\u70b9\u4e00\u4e0b", "id": "t/1032676" }, { "author": { "url": "member/datadump", "name": "datadump", "avatar": "https://cdn.v2ex.com/avatar/373a/9420/284506_large.png?m=1724288412" }, "url": "t/1021666", "title": "\u8bf7\u6559\u4e00\u4e2a opencv \u7b97\u6cd5\uff0c\u56fe\u7247\u4e2d\u68c0\u6d4b\u5706\u5f62\u5bf9\u8c61", "id": "t/1021666", "date_published": "2024-03-08T00:50:30+00:00", "content_html": "\u56fe\u7247\u53d1\u5230 2 \u697c\uff0c\u5927\u7ea6 2000x2000 \u7684\u56fe\u7247\uff0c\u76ee\u6807\u673a\u5668\u6ca1\u6709\u663e\u5361\u3002\u7b97\u6cd5\u65f6\u95f4\u53ef\u4ee5\u957f\u4e00\u70b9\uff0c\u5355\u5f20\u56fe\u7247 10 \u79d2\u4e5f\u53ef\u4ee5\u63a5\u53d7\u3002
\n\u6d4b\u4e86\u4e0b\u970d\u592b\u7b97\u6cd5\uff0c\u597d\u50cf\u65f6\u95f4\u592a\u957f\u4e86\uff0c\u800c\u4e14\u51c6\u786e\u5ea6\u4e5f\u6ca1\u6cd5\u4fdd\u969c\u3002
\n\u6c42\u4e00\u4e2a\u601d\u8def\uff08 opencv \u4e0d\u592a\u719f\uff0c\u91cc\u9762\u597d\u50cf\u6709 svm,cnn,dnn \u5565\u7684\u4e0d\u77e5\u9053\u662f\u5426\u5408\u9002\uff09\uff0c\u4e07\u5206\u611f\u8c22~~~
\n" }, { "author": { "url": "member/cooljiang", "name": "cooljiang", "avatar": "https://cdn.v2ex.com/avatar/bac2/6283/540574_large.png?m=1697639927" }, "url": "t/983293", "date_modified": "2023-10-18T14:55:01+00:00", "content_html": "\u5982\u9898\uff0csrc_image \u5927\u5c0f\u4e3a 100MB \uff0ctemplate_image \u5927\u5c0f\u4e3a 30MB \uff0c\u4f7f\u7528\u7684 match_method \u4e3a TM_CCOEFF_NORMED \u3002Python \u8c03\u7528\u7684\u662f OpenCV \u7684 C++\u63a5\u53e3\uff0c\u7406\u8bba\u4e0a C++\u76f4\u63a5\u8c03\u7528\u66f4\u5feb\u624d\u5bf9\u3002\u4f46\u5b9e\u9645\u6d4b\u8bd5\u65f6 Python \u7684\u8017\u65f6\u4e3a 5046ms \uff0c\u800c C++\u7684\u8017\u65f6\u4e3a 5681ms \u3002\u89c6\u9891\u662f iphone \u5f55\u5236\u7684 mov \u683c\u5f0f\uff0c\u73b0\u5728\u9700\u8981\u5bf9\u8be5\u89c6\u9891\u4e2d\u7684\u7b2c\u4e00\u5e27\u505a\u5904\u7406
\ncv::VideoCapture video;\nvideo.open(\"E:/20230612162536.MOV\");\nCV::Mat mat_1,mat_64F;\nvideo.read(mat_1);\nmat_1.converTo(mat_64F,CV_64F);\n\ncv::imshow(\"\u7b2c\u4e00\u5e27\",mat_1); //\u6b63\u5e38\u663e\u793a\u4e86\u56fe\u7247\ncv::imshow(\"\u7b2c\u4e00\u5e27 64 \u4f4d\",mat_64F); //\u663e\u793a\u6210\u7eaf\u767d\u56fe\u7247\uff0c\u5927\u5c0f\u548c mat_1 \u4e00\u6837\n\n\u6211\u73b0\u5728\u9700\u8981\u786e\u4fdd\u8fd9\u4e9b\u56fe\u7247\u90fd\u662f 64 \u4f4d\u6d6e\u70b9\uff0c\u6240\u4ee5\u4f7f\u7528\u4e86 converTo()\u8f6c\u6362\uff0c\u4f46\u8f6c\u6362\u4e4b\u540e\u5c31\u53d8\u6210\u7eaf\u767d\u56fe\u7247\u4e86
\n\u6211\u60f3\u95ee\u4e0b\uff0c\u5982\u4f55\u8f6c\u6362 mov \u4e2a\u6570\u7684\u67d0\u4e00\u5e27\uff0c\u786e\u4fdd\u8fd9\u4e00\u5e27\u56fe\u7247\u7684\u6570\u636e\u7c7b\u578b\u662f 64 \u4f4d\u6d6e\u70b9\uff1f
\n" }, { "author": { "url": "member/LeegoYih", "name": "LeegoYih", "avatar": "https://cdn.v2ex.com/avatar/7512/3f00/577498_large.png?m=1774264293" }, "url": "t/937788", "title": "\u5927\u5bb6\u6709\u7528\u8fc7\u7c7b\u4f3c PS Content-Aware Fill \u62a0\u56fe\u7684\u5e93\u6216\u6e90\u7801\u5417\uff08\u4e0d\u9650\u8bed\u8a00\uff09", "id": "t/937788", "date_published": "2023-05-06T02:56:17+00:00", "content_html": "\u60f3\u8981\u4ece\u7167\u7247\u4e2d\u79fb\u9664\u67d0\u4e2a\u4eba\u7269 /\u7269\u54c1\uff0c\u76ee\u524d\u4f7f\u7528\u4e86 OpenCV \u7684 inpaint \uff0c\u6548\u679c\u4e0d\u592a\u7406\u60f3\uff1a
\n
nii \u662f\u4e00\u4e2a 4d \u7684\u533b\u5b66 ct \u56fe\u50cf\uff0c\u5c3a\u5bf8\u4e3a\uff08\u9ad8\uff0c\u5bbd\uff0c\u6df1\u5ea6\uff0c\u65f6\u95f4\uff09\u3002
\n
\u6211\u7684\u9884\u671f\u662f, \u53d6\u65f6\u95f4\u548c\u53e6\u5916\u4e24\u4e2a\u7ef4\u5ea6\uff0c\u8f6c\u6362\u4e3a\u4e00\u4e2a mp4 \u683c\u5f0f\u7684\u89c6\u9891\u3002
\n\u6211\u7684\u601d\u8def\uff0c\u5148\u5c06 nii \u56fe\u7247\u8f6c\u6362\u4e00\u4e2a 2 \u7ef4\u7684\u6570\u7ec4\uff0c\u7136\u540e\u987a\u5e8f\u62fc\u6210\u4e00\u4e2a\u89c6\u9891\u3002
\n\u4f46\u662f\u5b9e\u9645, \u8f6c\u6362\u51fa\u6765\u7684\u89c6\u9891\u753b\u9762\u5931\u771f\uff0cwin11 \u7cfb\u7edf\u64ad\u653e\u5668\u6253\u5f00\u753b\u9762\u5931\u771f\uff0cqq \u5f71\u97f3\u64ad\u653e\u5668\u6253\u5f00\u63d0\u793a\u89c6\u9891\u5931\u6548\u3002
\n
\n
https://1drv.ms/u/s!Ah4q2HtKB2AWg4NnYXaMslribNVlWw?e=D8ScIs
\n\nimport os\nimport cv2\nimport numpy as np\n\n\ndef nii2imgs_dim(nii, dim) -> list:\n \"\"\"\n \u5c06 nii \u6587\u4ef6\u8f6c\u6362\u4e3a\u591a\u5f20\u56fe\u7247\uff0c\u8fd4\u56de\u56fe\u7247\u6570\u7ec4\uff0c\u4e0d\u7528\u4e2d\u95f4\u4fdd\u5b58\uff0c\u65b9\u4fbf\u8f6c\u6362\u4e3a\u89c6\u9891\n :param nii: nii \u5bf9\u8c61\n :param dim: \u8981\u8f6c\u6362\u7684\u7ef4\u5ea6\n :return: \u56fe\u7247\u6570\u7ec4\n \"\"\"\n imgs = []\n data = nii\n for d3i in range(data.shape[3]):\n # \u8bfb\u53d6 3d \u6587\u4ef6\n d3img = data[:, :, :, d3i]\n # \u83b7\u53d6 nii \u6587\u4ef6\u7684\u7ef4\u5ea6\n d3img_shape = d3img.shape\n # \u904d\u5386\u6bcf\u4e00\u5f20\u56fe\u7247\n for d2j in range(d3img_shape[2]):\n # \u83b7\u53d6\u7b2c i \u5f20\u56fe\u7247\n img = data[:, :, d2j, d3i]\n imgs.append(img)\n\n return imgs\n\ndef imgs2mp4(img_list, save_path):\n \"\"\"\n \u5c06\u56fe\u7247\u6570\u7ec4\u8f6c\u6362\u4e3a mp4\n :param img_list: \u56fe\u7247\u6570\u7ec4\n :param save_path: \u4fdd\u5b58\u5730\u5740\n :return: \u7a7a\n \"\"\"\n # \u5224\u65ad save_path \u8def\u5f84\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u5219\u521b\u5efa\n if not os.path.exists(save_path):\n os.makedirs(save_path)\n\n # \u56fe\u7247\u6570\u7ec4\u8f6c\u6362\u4e3a mp4\n img, *imgs = img_list # *imgs \u8868\u793a\u5269\u4e0b\u7684\u6240\u6709\u5143\u7d20\uff0cimg \u8868\u793a\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u76ee\u7684\u662f\u4e3a\u4e86\u83b7\u53d6\u56fe\u7247\u5c3a\u5bf8\n print(img.shape)\n # img \u8f6c\u6362\u4e3a float32\n img = img.astype(np.float32)\n img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)\n height, width, layers = img.shape\n video = cv2.VideoWriter(save_path + \"video.mp4\", cv2.VideoWriter_fourcc(*'mp4v'), 1, (width, height))\n video.write(img)\n for img in imgs:\n img = img.astype(np.float32)\n\n img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)\n\n video.write(img)\n video.release()\n\n\n\n\n\nimg = nib.load(file_path)\ndata = img.get_fdata()\n# nii \u8f6c\u6362\u4e3a\u591a\u5f20\u56fe\u7247\nimgs = nii2imgs_dim(data, 3)\n# \u5c06\u56fe\u7247\u6570\u7ec4\u8f6c\u6362\u4e3a mp4\nimgs2mp4(imgs, \"./tmp/\")\n\n" }, { "author": { "url": "member/fastdebuger", "name": "fastdebuger", "avatar": "https://cdn.v2ex.com/gravatar/6f8738191173ca6bfa9988fb61c41502?s=73&d=retro" }, "url": "t/832648", "title": "[\u6c42\u52a9] \u5982\u4f55\u786e\u5b9a\u70b9\u5728\u66f2\u7ebf\u4e2d\u7684\u4f4d\u7f6e", "id": "t/832648", "date_published": "2022-02-09T03:51:03+00:00", "content_html": "\u56fe\u7247\u4e0a\u6709\u4e00\u6761\u66f2\u7ebf\uff0c\u66f2\u7ebf\u4e0a\u5e26\u7740\u7bad\u5934\u548c\u4e00\u4e9b\u9ed1\u70b9\uff0c\u5982\u4f55\u5bf9\u66f2\u7ebf\u4e0a\u7684\u9ed1\u70b9\u6cbf\u7740\u7bad\u5934\u65b9\u5411\u6392\u5e8f" }, { "author": { "url": "member/blurh11E27", "name": "blurh11E27", "avatar": "https://cdn.v2ex.com/avatar/9626/727a/341739_large.png?m=1649906254" }, "url": "t/807744", "title": "\u54c7 \u671f\u5f85\u5f88\u4e45\u7684 \u8ba1\u7b97\u673a\u89c6\u89c9", "id": "t/807744", "date_published": "2021-10-14T03:03:25+00:00", "content_html": "\u6700\u8fd1\u60f3\u505a\u4e00\u4e2a\u89c6\u9891\u52a8\u6001\u4eba\u8138\u8bc6\u522b