├── .gitattributes ├── README.md ├── app └── app.go ├── device └── device.go ├── files └── files.go ├── go.mod ├── https └── https.go ├── images └── images.go ├── ime └── ime.go ├── imgui ├── imgui.go ├── imgui_386.go ├── imgui_amd64.go └── imgui_arm64.go ├── java └── java.go ├── media └── media.go ├── motion ├── keycode.go └── motion.go ├── opencv ├── cgo.go ├── core.cpp ├── core.go ├── core.h ├── core_string.go ├── imgproc.cpp ├── imgproc.go ├── imgproc.h ├── imgproc_colorcodes.go ├── imgproc_colorcodes_string.go ├── imgproc_string.go ├── mat_noprofile.go ├── opencv.go └── opencv2 │ ├── core.hpp │ ├── core │ ├── affine.hpp │ ├── async.hpp │ ├── base.hpp │ ├── bindings_utils.hpp │ ├── bufferpool.hpp │ ├── check.hpp │ ├── core.hpp │ ├── core_c.h │ ├── cuda.hpp │ ├── cuda.inl.hpp │ ├── cuda │ │ ├── block.hpp │ │ ├── border_interpolate.hpp │ │ ├── color.hpp │ │ ├── common.hpp │ │ ├── datamov_utils.hpp │ │ ├── detail │ │ │ ├── color_detail.hpp │ │ │ ├── reduce.hpp │ │ │ ├── reduce_key_val.hpp │ │ │ ├── transform_detail.hpp │ │ │ ├── type_traits_detail.hpp │ │ │ └── vec_distance_detail.hpp │ │ ├── dynamic_smem.hpp │ │ ├── emulation.hpp │ │ ├── filters.hpp │ │ ├── funcattrib.hpp │ │ ├── functional.hpp │ │ ├── limits.hpp │ │ ├── reduce.hpp │ │ ├── saturate_cast.hpp │ │ ├── scan.hpp │ │ ├── simd_functions.hpp │ │ ├── transform.hpp │ │ ├── type_traits.hpp │ │ ├── utility.hpp │ │ ├── vec_distance.hpp │ │ ├── vec_math.hpp │ │ ├── vec_traits.hpp │ │ ├── warp.hpp │ │ ├── warp_reduce.hpp │ │ └── warp_shuffle.hpp │ ├── cuda_stream_accessor.hpp │ ├── cuda_types.hpp │ ├── cv_cpu_dispatch.h │ ├── cv_cpu_helper.h │ ├── cvdef.h │ ├── cvstd.hpp │ ├── cvstd.inl.hpp │ ├── cvstd_wrapper.hpp │ ├── detail │ │ ├── async_promise.hpp │ │ ├── dispatch_helper.impl.hpp │ │ └── exception_ptr.hpp │ ├── directx.hpp │ ├── dualquaternion.hpp │ ├── dualquaternion.inl.hpp │ ├── eigen.hpp │ ├── fast_math.hpp │ ├── hal │ │ ├── hal.hpp │ │ ├── interface.h │ │ ├── intrin.hpp │ │ ├── intrin_avx.hpp │ │ ├── intrin_avx512.hpp │ │ ├── intrin_cpp.hpp │ │ ├── intrin_forward.hpp │ │ ├── intrin_lasx.hpp │ │ ├── intrin_lsx.hpp │ │ ├── intrin_msa.hpp │ │ ├── intrin_neon.hpp │ │ ├── intrin_rvv.hpp │ │ ├── intrin_rvv071.hpp │ │ ├── intrin_rvv_010_compat_non-policy.hpp │ │ ├── intrin_rvv_010_compat_overloaded-non-policy.hpp │ │ ├── intrin_rvv_011_compat.hpp │ │ ├── intrin_rvv_compat_overloaded.hpp │ │ ├── intrin_rvv_scalable.hpp │ │ ├── intrin_sse.hpp │ │ ├── intrin_sse_em.hpp │ │ ├── intrin_vsx.hpp │ │ ├── intrin_wasm.hpp │ │ ├── msa_macros.h │ │ └── simd_utils.impl.hpp │ ├── mat.hpp │ ├── mat.inl.hpp │ ├── matx.hpp │ ├── matx.inl.hpp │ ├── neon_utils.hpp │ ├── ocl.hpp │ ├── ocl_genbase.hpp │ ├── opencl │ │ ├── ocl_defs.hpp │ │ ├── opencl_info.hpp │ │ ├── opencl_svm.hpp │ │ └── runtime │ │ │ ├── autogenerated │ │ │ ├── opencl_clblas.hpp │ │ │ ├── opencl_clfft.hpp │ │ │ ├── opencl_core.hpp │ │ │ ├── opencl_core_wrappers.hpp │ │ │ ├── opencl_gl.hpp │ │ │ └── opencl_gl_wrappers.hpp │ │ │ ├── opencl_clblas.hpp │ │ │ ├── opencl_clfft.hpp │ │ │ ├── opencl_core.hpp │ │ │ ├── opencl_core_wrappers.hpp │ │ │ ├── opencl_gl.hpp │ │ │ ├── opencl_gl_wrappers.hpp │ │ │ ├── opencl_svm_20.hpp │ │ │ ├── opencl_svm_definitions.hpp │ │ │ └── opencl_svm_hsa_extension.hpp │ ├── opengl.hpp │ ├── operations.hpp │ ├── optim.hpp │ ├── ovx.hpp │ ├── parallel │ │ ├── backend │ │ │ ├── parallel_for.openmp.hpp │ │ │ └── parallel_for.tbb.hpp │ │ └── parallel_backend.hpp │ ├── persistence.hpp │ ├── quaternion.hpp │ ├── quaternion.inl.hpp │ ├── saturate.hpp │ ├── simd_intrinsics.hpp │ ├── softfloat.hpp │ ├── sse_utils.hpp │ ├── traits.hpp │ ├── types.hpp │ ├── types_c.h │ ├── utility.hpp │ ├── utils │ │ ├── allocator_stats.hpp │ │ ├── allocator_stats.impl.hpp │ │ ├── filesystem.hpp │ │ ├── fp_control_utils.hpp │ │ ├── instrumentation.hpp │ │ ├── logger.defines.hpp │ │ ├── logger.hpp │ │ ├── logtag.hpp │ │ ├── tls.hpp │ │ └── trace.hpp │ ├── va_intel.hpp │ ├── version.hpp │ └── vsx_utils.hpp │ ├── cvconfig.h │ ├── imgproc.hpp │ ├── imgproc │ ├── bindings.hpp │ ├── detail │ │ ├── gcgraph.hpp │ │ └── legacy.hpp │ ├── hal │ │ ├── hal.hpp │ │ └── interface.h │ ├── imgproc.hpp │ ├── imgproc_c.h │ ├── segmentation.hpp │ └── types_c.h │ ├── opencv.hpp │ └── opencv_modules.hpp ├── plugin └── plugin.go ├── ppocr ├── ppocr.go └── ppocr.h ├── storages └── storages.go ├── system └── system.go ├── uiacc └── uiacc.go ├── utils └── utils.go └── yolov5 ├── yolov5.go └── yolov5.h /.gitattributes: -------------------------------------------------------------------------------- 1 | * linguist-language=Go -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoGo —— 高性能 Android 自动化测试框架 2 | 3 | **AutoGo** 是一个基于 Go 语言开发的 Android 自动化操作工具,旨在为用户提供一个高效、安全、灵活的 Android 自动化解决方案。与传统的自动化工具不同,AutoGo 的二进制执行文件能够在 Android 系统上直接运行,具备强大的跨应用操作能力,同时无需安装任何 APK。这使得它在复杂的自动化场景中,尤其是在需要与其他应用无缝交互时,具有独特的优势。 4 | 5 | # [访问官网](https://autogo.cc) -------------------------------------------------------------------------------- /app/app.go: -------------------------------------------------------------------------------- 1 | package app 2 | 3 | import ( 4 | "github.com/Dasongzi1366/AutoGo/utils" 5 | "mime" 6 | "path/filepath" 7 | "regexp" 8 | "strings" 9 | ) 10 | 11 | type IntentOptions struct { 12 | Action string 13 | Type string 14 | Data string 15 | Category []string 16 | PackageName string 17 | ClassName string 18 | Extras map[string]string 19 | Flags []string 20 | } 21 | 22 | // GetPackageAndClass 获取当前页面应用包名和类名 23 | func GetPackageAndClass() (string, string) { 24 | re := regexp.MustCompile(`mCurrentFocus=Window\{[^}]+\s([^\s/]+)/([^\s}]+)`) 25 | output := utils.Shell("dumpsys window | grep mCurrentFocus") 26 | match := re.FindStringSubmatch(output) 27 | if len(match) > 2 { 28 | return match[1], match[2] 29 | } 30 | return "", "" 31 | } 32 | 33 | // Launch 通过应用包名启动应用。如果该包名对应的应用不存在,则返回false;否则返回true。 34 | func Launch(packageName string) bool { 35 | return strings.Contains(utils.Shell("am start -n $(cmd package resolve-activity --brief "+packageName+" android.intent.action.MAIN | grep "+packageName+"/)"), "Starting") 36 | } 37 | 38 | // OpenAppSetting 打开应用的详情页(设置页)。如果找不到该应用,返回false; 否则返回true。 39 | func OpenAppSetting(packageName string) bool { 40 | return !strings.Contains(utils.Shell(`am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d "package:"+packageName`), "Error:") 41 | } 42 | 43 | // ViewFile 用其他应用查看文件。文件不存在的情况由查看文件的应用处理。 44 | func ViewFile(path string) { 45 | StartActivity(IntentOptions{ 46 | Action: "VIEW", 47 | Type: getMimeType(path), 48 | Data: "file://" + path, 49 | }) 50 | } 51 | 52 | // EditFile 用其他应用编辑文件。文件不存在的情况由编辑文件的应用处理 53 | func EditFile(path string) { 54 | StartActivity(IntentOptions{ 55 | Action: "EDIT", 56 | Type: getMimeType(path), 57 | Data: "file://" + path, 58 | }) 59 | } 60 | 61 | // Uninstall 卸载应用 62 | func Uninstall(packageName string) { 63 | utils.Shell("pm uninstall " + packageName) 64 | } 65 | 66 | // Install 安装应用 67 | func Install(path string) { 68 | utils.Shell("cp -rf " + path + " /data/local/tmp/1.apk;pm install -r /data/local/tmp/1.apk") 69 | } 70 | 71 | // IsInstalled 判断是否已经安装某个应用 72 | func IsInstalled(packageName string) bool { 73 | return utils.Shell("pm list packages | grep "+packageName) != "" 74 | } 75 | 76 | // Clear 清除应用数据 77 | func Clear(packageName string) { 78 | utils.Shell("pm clear " + packageName) 79 | } 80 | 81 | // ForceStop 强制停止应用 82 | func ForceStop(packageName string) { 83 | utils.Shell("am force-stop " + packageName) 84 | } 85 | 86 | // Disable 禁用应用 87 | func Disable(packageName string) { 88 | utils.Shell("pm disable-user " + packageName) 89 | } 90 | 91 | // Enable 启用应用 92 | func Enable(packageName string) { 93 | utils.Shell("pm enable " + packageName) 94 | } 95 | 96 | // OpenUrl 用浏览器打开网站url。 97 | func OpenUrl(url string) { 98 | if !strings.HasPrefix(url, "http://") && !strings.HasPrefix(url, "https://") { 99 | url = "http://" + url 100 | } 101 | StartActivity(IntentOptions{ 102 | Action: "VIEW", 103 | Data: url, 104 | }) 105 | } 106 | 107 | // StartActivity 根据选项构造一个Intent,并启动该Activity。 108 | func StartActivity(options IntentOptions) { 109 | utils.Shell(buildIntentCommand(options, "start")) 110 | } 111 | 112 | // SendBroadcast 根据选项构造一个Intent,并发送该广播。 113 | func SendBroadcast(options IntentOptions) { 114 | utils.Shell(buildIntentCommand(options, "broadcast")) 115 | } 116 | 117 | // StartService 根据选项构造一个Intent,并启动该服务。 118 | func StartService(options IntentOptions) { 119 | utils.Shell(buildIntentCommand(options, "startservice")) 120 | } 121 | 122 | func buildIntentCommand(options IntentOptions, commandType string) string { 123 | var commandBuilder strings.Builder 124 | 125 | commandBuilder.WriteString("am " + commandType) 126 | 127 | if options.Action != "" { 128 | if strings.HasPrefix(options.Action, "android.intent.action.") { 129 | commandBuilder.WriteString(" -a " + options.Action) 130 | } else { 131 | commandBuilder.WriteString(" -a android.intent.action." + options.Action) 132 | } 133 | } 134 | 135 | if options.Type != "" { 136 | commandBuilder.WriteString(" -t " + options.Type) 137 | } 138 | 139 | if options.Data != "" { 140 | commandBuilder.WriteString(" -d " + options.Data) 141 | } 142 | 143 | for _, category := range options.Category { 144 | commandBuilder.WriteString(" -c " + category) 145 | } 146 | 147 | if options.PackageName != "" { 148 | commandBuilder.WriteString(" -n " + options.PackageName) 149 | if options.ClassName != "" { 150 | commandBuilder.WriteString("/" + options.ClassName) 151 | } 152 | } 153 | 154 | for key, value := range options.Extras { 155 | commandBuilder.WriteString(" --es " + key + " \"" + value + "\"") 156 | } 157 | 158 | for _, flag := range options.Flags { 159 | commandBuilder.WriteString(" --ez " + flag) 160 | } 161 | 162 | return commandBuilder.String() 163 | } 164 | 165 | func getMimeType(path string) string { 166 | ext := strings.ToLower(filepath.Ext(path)) 167 | switch ext { 168 | case ".jpg", ".jpeg": 169 | return "image/jpeg" 170 | case ".png": 171 | return "image/png" 172 | case ".gif": 173 | return "image/gif" 174 | case ".txt": 175 | return "text/plain" 176 | case ".pdf": 177 | return "application/pdf" 178 | case ".apk": 179 | return "application/vnd.android.package-archive" 180 | case ".mp3": 181 | return "audio/mpeg" 182 | case ".wav": 183 | return "audio/wav" 184 | case ".ogg": 185 | return "audio/ogg" 186 | case ".flac": 187 | return "audio/flac" 188 | case ".aac": 189 | return "audio/aac" 190 | case ".m4a": 191 | return "audio/mp4" 192 | default: 193 | // Try to detect mime type based on file extension 194 | mimeType := mime.TypeByExtension(ext) 195 | if mimeType == "" { 196 | return "*/*" 197 | } 198 | return mimeType 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /files/files.go: -------------------------------------------------------------------------------- 1 | package files 2 | 3 | import "C" 4 | import ( 5 | "io" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | ) 10 | 11 | // IsFile 返回路径path是否是文件。 12 | func IsFile(path string) bool { 13 | info, err := os.Stat(path) 14 | if err != nil { 15 | return false 16 | } 17 | return !info.IsDir() 18 | } 19 | 20 | // IsDir 返回路径path是否是文件夹。 21 | func IsDir(path string) bool { 22 | info, err := os.Stat(path) 23 | if err != nil { 24 | return false 25 | } 26 | return info.IsDir() 27 | } 28 | 29 | // IsEmptyDir 返回文件夹path是否为空文件夹。如果该路径并非文件夹,则直接返回false。 30 | func IsEmptyDir(path string) bool { 31 | info, err := os.Stat(path) 32 | if err != nil || !info.IsDir() { 33 | return false 34 | } 35 | files, err := os.ReadDir(path) 36 | if err != nil { 37 | return false 38 | } 39 | return len(files) == 0 40 | } 41 | 42 | // Create 创建一个文件或文件夹并返回是否创建成功。如果文件已经存在,则直接返回false。 43 | func Create(path string) bool { 44 | _, err := os.Stat(path) 45 | if err == nil { 46 | // 文件或文件夹已经存在 47 | return false 48 | } 49 | if os.IsNotExist(err) { 50 | // 尝试创建文件夹 51 | if filepath.Ext(path) == "" { 52 | err = os.Mkdir(path, 0755) 53 | } else { 54 | // 尝试创建文件 55 | file, err := os.Create(path) 56 | if err != nil { 57 | return false 58 | } 59 | _ = file.Close() 60 | } 61 | } 62 | return err == nil 63 | } 64 | 65 | // CreateWithDirs 创建一个文件或文件夹并返回是否创建成功。如果文件所在文件夹不存在,则先创建它所在的一系列文件夹。如果文件已经存在,则直接返回false。 66 | func CreateWithDirs(path string) bool { 67 | _, err := os.Stat(path) 68 | if err == nil { 69 | // 文件或文件夹已经存在 70 | return false 71 | } 72 | if os.IsNotExist(err) { 73 | // 确保路径中的所有文件夹存在 74 | err = os.MkdirAll(filepath.Dir(path), 0755) 75 | if err != nil { 76 | return false 77 | } 78 | // 尝试创建文件 79 | file, err := os.Create(path) 80 | if err != nil { 81 | return false 82 | } 83 | _ = file.Close() 84 | } 85 | return err == nil 86 | } 87 | 88 | // Exists 返回在路径path处的文件是否存在。 89 | func Exists(path string) bool { 90 | _, err := os.Stat(path) 91 | return err == nil 92 | } 93 | 94 | // EnsureDir 确保路径path所在的文件夹存在。如果该路径所在文件夹不存在,则创建该文件夹。 95 | func EnsureDir(path string) bool { 96 | return os.MkdirAll(filepath.Dir(path), 0755) == nil 97 | } 98 | 99 | // Read 读取文本文件path的所有内容并返回。 100 | func Read(path string) string { 101 | data, err := os.ReadFile(path) 102 | if err != nil { 103 | return "" 104 | } 105 | return string(data) 106 | } 107 | 108 | // ReadBytes 读取文件path的所有内容并返回。 109 | func ReadBytes(path string) []byte { 110 | data, err := os.ReadFile(path) 111 | if err != nil { 112 | return nil 113 | } 114 | return data 115 | } 116 | 117 | // Write 把text写入到文件path中。如果文件存在则覆盖,不存在则创建。 118 | func Write(path, text string) { 119 | _ = os.WriteFile(path, []byte(text), 0644) 120 | } 121 | 122 | // WriteBytes 把bytes写入到文件path中。如果文件存在则覆盖,不存在则创建。 123 | func WriteBytes(path string, bytes []byte) { 124 | Remove(path) 125 | _ = os.WriteFile(path, bytes, 0644) 126 | } 127 | 128 | // Append 把text追加到文件path的末尾。如果文件不存在则创建。 129 | func Append(path string, text string) { 130 | // 以追加模式打开文件,如果文件不存在则创建 131 | file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) 132 | if err != nil { 133 | return 134 | } 135 | defer file.Close() 136 | // 将文本写入文件末尾 137 | _, _ = file.WriteString(text) 138 | } 139 | 140 | // AppendBytes 把bytes追加到文件path的末尾。如果文件不存在则创建。 141 | func AppendBytes(path string, bytes []byte) { 142 | // 以追加模式打开文件,如果文件不存在则创建 143 | file, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) 144 | if err != nil { 145 | return 146 | } 147 | defer file.Close() 148 | // 将字节数组写入文件末尾 149 | _, _ = file.Write(bytes) 150 | } 151 | 152 | // Copy 复制文件,返回是否复制成功。 153 | func Copy(fromPath, toPath string) bool { 154 | sourceFile, err := os.Open(fromPath) 155 | if err != nil { 156 | return false 157 | } 158 | defer sourceFile.Close() 159 | 160 | destFile, err := os.Create(toPath) 161 | if err != nil { 162 | return false 163 | } 164 | defer destFile.Close() 165 | 166 | _, err = io.Copy(destFile, sourceFile) 167 | return err == nil 168 | } 169 | 170 | // Move 移动文件,返回是否移动成功。 171 | func Move(fromPath, toPath string) bool { 172 | return os.Rename(fromPath, toPath) == nil 173 | } 174 | 175 | // Rename 重命名文件,并返回是否重命名成功。 176 | func Rename(path, newName string) bool { 177 | return os.Rename(path, newName) == nil 178 | } 179 | 180 | // GetName 返回文件的文件名。例如files.getName("/sdcard/1.txt")返回"1.txt"。 181 | func GetName(path string) string { 182 | return filepath.Base(path) 183 | } 184 | 185 | // GetNameWithoutExtension 返回不含拓展名的文件的文件名。例如files.getName("/sdcard/1.txt")返回"1"。 186 | func GetNameWithoutExtension(path string) string { 187 | filename := filepath.Base(path) 188 | ext := filepath.Ext(filename) 189 | return strings.TrimSuffix(filename, ext) 190 | } 191 | 192 | // GetExtension 返回文件的拓展名。例如files.getExtension("/sdcard/1.txt")返回"txt"。 193 | func GetExtension(path string) string { 194 | ext := filepath.Ext(path) 195 | if len(ext) > 0 && ext[0] == '.' { 196 | return ext[1:] 197 | } 198 | return ext 199 | } 200 | 201 | // Remove 删除文件或文件夹,如果是文件夹会删除整个文件夹包含里面的所有文件,返回是否删除成功。 202 | func Remove(path string) bool { 203 | return os.RemoveAll(path) == nil 204 | } 205 | 206 | // Path 返回相对路径对应的绝对路径。例如files.path("./1.png"),如果运行这个语句的脚本位于文件夹"/sdcard/脚本/"中,则返回"/sdcard/脚本/1.png"。 207 | func Path(relativePath string) string { 208 | appDir := filepath.Dir(os.Args[0]) 209 | if relativePath[:2] == "./" { 210 | return appDir + relativePath[1:] 211 | } 212 | return appDir + "/" + relativePath 213 | } 214 | 215 | // ListDir 列出文件夹path下的所有文件和文件夹 216 | func ListDir(path string) []string { 217 | var entries []string 218 | dir, err := os.Open(path) 219 | if err != nil { 220 | return nil 221 | } 222 | defer dir.Close() 223 | files, err := dir.Readdir(-1) 224 | if err != nil { 225 | return nil 226 | } 227 | for _, file := range files { 228 | entries = append(entries, filepath.Join(path, file.Name())) 229 | } 230 | return entries 231 | } 232 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Dasongzi1366/AutoGo 2 | 3 | go 1.23.0 4 | -------------------------------------------------------------------------------- /https/https.go: -------------------------------------------------------------------------------- 1 | package https 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "mime/multipart" 7 | "net/http" 8 | "time" 9 | ) 10 | 11 | func Get(url string, timeout int) (code int, data []byte) { 12 | var client http.Client 13 | 14 | // 如果 timeout 不为 0,设置超时,否则使用默认的 client(没有超时) 15 | if timeout > 0 { 16 | client = http.Client{ 17 | Timeout: time.Duration(timeout) * time.Millisecond, 18 | } 19 | } else { 20 | client = http.Client{} 21 | } 22 | 23 | resp, err := client.Get(url) 24 | if err != nil { 25 | return 0, nil 26 | } 27 | defer resp.Body.Close() 28 | 29 | body, _ := io.ReadAll(resp.Body) 30 | return resp.StatusCode, body 31 | } 32 | 33 | func PostMultipart(url string, fileName string, fileData []byte) (code int, data []byte) { 34 | // 创建一个缓冲区用于存储 multipart 数据 35 | var buffer bytes.Buffer 36 | writer := multipart.NewWriter(&buffer) 37 | 38 | // 创建一个 form 文件字段 39 | part, err := writer.CreateFormFile("file", fileName) 40 | if err != nil { 41 | return 0, nil 42 | } 43 | 44 | // 将文件数据写入 part 45 | if _, err = io.Copy(part, bytes.NewReader(fileData)); err != nil { 46 | return 0, nil 47 | } 48 | 49 | // 关闭 multipart writer,设置结束标志 50 | _ = writer.Close() 51 | 52 | // 创建 HTTP 请求 53 | req, err := http.NewRequest("POST", url, &buffer) 54 | if err != nil { 55 | return 0, nil 56 | } 57 | req.Header.Set("Content-Type", writer.FormDataContentType()) 58 | 59 | // 发送请求 60 | client := &http.Client{} 61 | resp, err := client.Do(req) 62 | if err != nil { 63 | return 0, nil 64 | } 65 | defer resp.Body.Close() 66 | 67 | // 读取响应内容 68 | body, err := io.ReadAll(resp.Body) 69 | if err != nil { 70 | return 0, nil 71 | } 72 | 73 | return resp.StatusCode, body 74 | } 75 | -------------------------------------------------------------------------------- /ime/ime.go: -------------------------------------------------------------------------------- 1 | package ime 2 | 3 | import ( 4 | "bufio" 5 | "strconv" 6 | "strings" 7 | "time" 8 | 9 | "github.com/Dasongzi1366/AutoGo/java" 10 | "github.com/Dasongzi1366/AutoGo/motion" 11 | "github.com/Dasongzi1366/AutoGo/utils" 12 | ) 13 | 14 | // GetClipText 获取剪切板内容 15 | func GetClipText() string { 16 | return java.CallJavaMethod("utils", "getClipText") 17 | } 18 | 19 | // SetClipText 设置剪切板内容 20 | func SetClipText(text string) bool { 21 | return java.CallJavaMethod("utils", "setClipText|"+text) == "true" 22 | } 23 | 24 | // InputText 输入文本 25 | func InputText(text string) { 26 | // 判断字符串是否包含中文 27 | if containsChinese(text) { 28 | SetClipText(text) 29 | motion.KeyAction(279) 30 | time.Sleep(time.Duration(30) * time.Millisecond) 31 | SetClipText("") 32 | } else { 33 | // 如果不包含中文,则使用 Shell 输入文本 34 | utils.Shell("input text " + strconv.Quote(text)) 35 | } 36 | } 37 | 38 | // KeyAction 模拟按键 39 | func KeyAction(code int) { 40 | utils.Shell("am broadcast -a com.autogo --es message keyaction --es data " + strconv.Itoa(code)) 41 | } 42 | 43 | // GetIMEList 获取输入法列表 44 | func GetIMEList() []string { 45 | shellOutput := utils.Shell("ime list -a | grep mId") 46 | 47 | var imeList []string 48 | 49 | scanner := bufio.NewScanner(strings.NewReader(shellOutput)) 50 | for scanner.Scan() { 51 | line := scanner.Text() 52 | line = strings.TrimSpace(line) 53 | if strings.HasPrefix(line, "mId=") { 54 | mId := strings.SplitN(line, " ", 2)[0] 55 | mId = strings.TrimPrefix(mId, "mId=") 56 | imeList = append(imeList, mId) 57 | } 58 | } 59 | 60 | if err := scanner.Err(); err != nil { 61 | //fmt.Println("Scanner error:", err) 62 | return nil 63 | } 64 | 65 | return imeList 66 | } 67 | 68 | // SetCurrentIME 设置当前输入法 69 | func SetCurrentIME(imeID string) { 70 | utils.Shell("ime enable " + imeID) 71 | utils.Shell("ime set " + imeID) 72 | } 73 | 74 | // containsChinese 检查字符串是否包含中文 75 | func containsChinese(s string) bool { 76 | for _, r := range s { 77 | if r >= '\u4e00' && r <= '\u9fff' { // 中文字符范围 78 | return true 79 | } 80 | } 81 | return false 82 | } 83 | -------------------------------------------------------------------------------- /imgui/imgui_386.go: -------------------------------------------------------------------------------- 1 | //go:build 386 2 | // +build 386 3 | 4 | package imgui 5 | 6 | var _imgui []byte 7 | -------------------------------------------------------------------------------- /imgui/imgui_amd64.go: -------------------------------------------------------------------------------- 1 | //go:build amd64 2 | // +build amd64 3 | 4 | package imgui 5 | 6 | import _ "embed" 7 | 8 | //go:embed imgui_amd64 9 | var _imgui []byte 10 | -------------------------------------------------------------------------------- /imgui/imgui_arm64.go: -------------------------------------------------------------------------------- 1 | //go:build arm64 2 | // +build arm64 3 | 4 | package imgui 5 | 6 | import _ "embed" 7 | 8 | //go:embed imgui_arm64 9 | var _imgui []byte 10 | -------------------------------------------------------------------------------- /java/java.go: -------------------------------------------------------------------------------- 1 | package java 2 | 3 | /* 4 | #include 5 | #include 6 | #cgo arm64 LDFLAGS: -L../libs/arm64-v8a -lAutoGo 7 | #cgo amd64 LDFLAGS: -L../libs/x86_64 -lAutoGo 8 | #cgo 386 LDFLAGS: -L../libs/x86 -lAutoGo 9 | 10 | int shmem_create(const char *name, size_t size); 11 | int shmem_read(void *buffer, size_t buffer_size, int clear_data); 12 | int shmem_getfb(); 13 | */ 14 | import "C" 15 | import ( 16 | "bufio" 17 | _ "embed" 18 | "fmt" 19 | "github.com/Dasongzi1366/AutoGo/utils" 20 | "io" 21 | "net" 22 | "os" 23 | "path/filepath" 24 | "regexp" 25 | "runtime" 26 | "strconv" 27 | "strings" 28 | "sync" 29 | "time" 30 | "unsafe" 31 | ) 32 | 33 | //go:embed utils.dex 34 | var _utils []byte 35 | 36 | //go:embed libashmem_arm64.so 37 | var _libashmem_arm64 []byte 38 | 39 | //go:embed libashmem_amd64.so 40 | var _libashmem_amd64 []byte 41 | 42 | //go:embed libashmem_amd.so 43 | var _libashmem_amd []byte 44 | 45 | var conn net.Conn 46 | var msgChanMap = make(map[string]chan string) 47 | var mu sync.Mutex 48 | var currentMsgId int 49 | 50 | func init() { 51 | path := filepath.Dir(os.Args[0]) 52 | width, height := getWmSize() 53 | size := (width + 40) * (height + 40) * 4 54 | handleError(shmemCreate("my_shared_memory", size)) 55 | fd := shmemGetFD() 56 | listen, err := net.Listen("tcp", ":56788") 57 | handleError(err) 58 | utils.Shell("pkill -f com.autogo.Main") 59 | if runtime.GOARCH == "arm64" { 60 | _ = os.WriteFile(path+"/libashmem.so", _libashmem_arm64, 0644) 61 | } else if runtime.GOARCH == "amd64" { 62 | _ = os.WriteFile(path+"/libashmem.so", _libashmem_amd64, 0644) 63 | } else { 64 | _ = os.WriteFile(path+"/libashmem.so", _libashmem_amd, 0644) 65 | } 66 | _ = os.WriteFile(path+"/autogo.dex", _utils, 0644) 67 | go func() { 68 | cmdStr := "app_process -Djava.class.path=" + path + "/autogo.dex / com.autogo.Main " + fmt.Sprintf("%s %d %d", "56788", fd, size) 69 | cCmd := C.CString(cmdStr) 70 | defer C.free(unsafe.Pointer(cCmd)) 71 | C.system(cCmd) 72 | _, _ = fmt.Fprintln(os.Stderr, "[AutoGo] 服务异常崩溃") 73 | os.Exit(1) 74 | }() 75 | conn, err = listen.Accept() 76 | _ = os.Remove(path + "/autogo.dex") 77 | handleError(err) 78 | go func() { 79 | reader := bufio.NewReader(conn) 80 | for { 81 | // 先读取消息ID和消息长度,共12个字节 82 | header := make([]byte, 12) 83 | _, err = reader.Read(header) 84 | if err != nil { 85 | fmt.Println("Error reading message header:", err) 86 | return 87 | } 88 | // 解析消息ID(前6个字节) 89 | msgId := string(header[:6]) 90 | 91 | // 解析消息长度(后6个字节) 92 | lengthStr := string(header[6:12]) 93 | msgLength, err := strconv.Atoi(lengthStr) 94 | if err != nil { 95 | fmt.Println("Error parsing message length:", err) 96 | return 97 | } 98 | 99 | // 读取消息体 100 | message := make([]byte, msgLength) 101 | _, err = io.ReadFull(reader, message) 102 | if err != nil { 103 | fmt.Println("Error reading message body:", err) 104 | return 105 | } 106 | 107 | // 将消息发送到对应的通道 108 | mu.Lock() 109 | if ch, ok := msgChanMap[msgId]; ok { 110 | ch <- string(message) 111 | close(ch) 112 | delete(msgChanMap, msgId) 113 | } 114 | mu.Unlock() 115 | } 116 | }() 117 | } 118 | 119 | func CallJavaMethod(model string, str string) string { 120 | respChan := make(chan string) 121 | mu.Lock() 122 | currentMsgId++ 123 | if currentMsgId > 999999 { 124 | currentMsgId = 1 125 | } 126 | msgId := fmt.Sprintf("%06d", currentMsgId) 127 | _, _ = conn.Write([]byte(model + "|" + msgId + "|" + str + "\n")) 128 | msgChanMap[msgId] = respChan 129 | mu.Unlock() 130 | select { 131 | case resp := <-respChan: 132 | mu.Lock() 133 | delete(msgChanMap, msgId) // 收到响应后清理 map 134 | mu.Unlock() 135 | return resp 136 | case <-time.After(10 * time.Second): 137 | mu.Lock() 138 | delete(msgChanMap, msgId) // 超时后清理 map 139 | mu.Unlock() 140 | fmt.Println("Timeout waiting for response") 141 | return "" 142 | } 143 | } 144 | 145 | func Send(str string) { 146 | mu.Lock() 147 | _, _ = conn.Write([]byte(str + "\n")) 148 | mu.Unlock() 149 | } 150 | 151 | func GetBitMapData() ([]byte, error) { 152 | return shmemRead(1) 153 | } 154 | 155 | func shmemCreate(name string, size int) error { 156 | cName := C.CString(name) 157 | defer C.free(unsafe.Pointer(cName)) 158 | 159 | ret := C.shmem_create(cName, C.size_t(size)) 160 | if ret < 0 { 161 | return fmt.Errorf("failed to create ashmem") 162 | } 163 | 164 | return nil 165 | } 166 | 167 | func shmemRead(clearData int) ([]byte, error) { 168 | // 第一次读取时,传入 nil 来获取数据长度 169 | dataLen := int(C.shmem_read(nil, 0, 0)) // 先获取数据长度 170 | if dataLen < 0 { 171 | return nil, fmt.Errorf("failed to get data length from shared memory") 172 | } 173 | 174 | if dataLen == 0 { 175 | return nil, nil 176 | } 177 | 178 | // 创建一个大小为 dataLen 的缓冲区 179 | buffer := make([]byte, dataLen) 180 | 181 | // 读取数据到缓冲区,传入 clearData 参数 182 | bufferPtr := unsafe.Pointer(&buffer[0]) 183 | readSize := C.shmem_read(bufferPtr, C.size_t(len(buffer)), C.int(clearData)) 184 | if int(readSize) != dataLen { 185 | return nil, fmt.Errorf("buffer size mismatch: expected %d, got %d", dataLen, int(readSize)) 186 | } 187 | 188 | return buffer, nil 189 | } 190 | 191 | func shmemGetFD() int { 192 | return int(C.shmem_getfb()) 193 | } 194 | 195 | func handleError(err error) { 196 | if err != nil { 197 | fmt.Fprintf(os.Stderr, "[AutoGo] 出现错误:", err) 198 | os.Exit(1) 199 | } 200 | } 201 | 202 | func getWmSize() (int, int) { 203 | input := utils.Shell("wm size") 204 | lastLine := strings.Split(input, "\n")[len(strings.Split(input, "\n"))-1] 205 | re := regexp.MustCompile(`(\d+)x(\d+)`) 206 | matches := re.FindStringSubmatch(lastLine) 207 | if len(matches) == 3 { 208 | return s2i(matches[1]), s2i(matches[2]) 209 | } 210 | fmt.Fprintln(os.Stderr, "[AutoGo] 设备分辨率获取失败") 211 | os.Exit(1) 212 | return 0, 0 213 | } 214 | 215 | func s2i(s string) int { 216 | i, _ := strconv.Atoi(strings.TrimSpace(s)) 217 | return i 218 | } 219 | -------------------------------------------------------------------------------- /media/media.go: -------------------------------------------------------------------------------- 1 | package media 2 | 3 | /* 4 | #include 5 | #include 6 | */ 7 | import "C" 8 | import ( 9 | "strings" 10 | "unsafe" 11 | ) 12 | 13 | // ScanFile 扫描路径path的媒体文件,将它加入媒体库中 14 | func ScanFile(path string) { 15 | shell("am broadcast -a android.intent.action.MEDIA_SCANNER_SCAN_FILE -d file://" + path) 16 | } 17 | 18 | func shell(cmd string) { 19 | if strings.Contains(cmd, ";") { 20 | cmd = "(" + cmd + ")" 21 | } 22 | cCmd := C.CString(cmd + " > /dev/null 2>&1") 23 | defer C.free(unsafe.Pointer(cCmd)) 24 | C.system(cCmd) 25 | } 26 | -------------------------------------------------------------------------------- /motion/motion.go: -------------------------------------------------------------------------------- 1 | package motion 2 | 3 | /* 4 | #include 5 | #include 6 | */ 7 | import "C" 8 | import ( 9 | "fmt" 10 | "github.com/Dasongzi1366/AutoGo/java" 11 | "math/rand" 12 | "strings" 13 | "time" 14 | "unsafe" 15 | ) 16 | 17 | func TouchDown(x, y, fingerID int) { 18 | fingerID = fingerID - 1 19 | if fingerID < 0 || fingerID > 9 { 20 | fingerID = 0 21 | } 22 | java.Send(fmt.Sprintf("d|%d|%d|%d", x, y, fingerID)) 23 | } 24 | 25 | func TouchMove(x, y, fingerID int) { 26 | fingerID = fingerID - 1 27 | if fingerID < 0 || fingerID > 9 { 28 | fingerID = 0 29 | } 30 | java.Send(fmt.Sprintf("m|%d|%d|%d", x, y, fingerID)) 31 | } 32 | 33 | func TouchUp(x, y, fingerID int) { 34 | fingerID = fingerID - 1 35 | if fingerID < 0 || fingerID > 9 { 36 | fingerID = 0 37 | } 38 | java.Send(fmt.Sprintf("u|%d|%d|%d", x, y, fingerID)) 39 | } 40 | 41 | func Click(x, y, fingerID int) { 42 | TouchDown(x, y, fingerID) 43 | sleep(random(10, 20)) 44 | TouchUp(x, y, fingerID) 45 | } 46 | 47 | func LongClick(x, y, duration int) { 48 | TouchDown(x, y, 1) 49 | sleep(duration + random(1, 20)) 50 | TouchUp(x, y, 1) 51 | } 52 | 53 | func Swipe(x1, y1, x2, y2, duration int) { 54 | java.Send(fmt.Sprintf("s1|%d|%d|%d|%d|%d", x1, y1, x2, y2, duration)) 55 | } 56 | 57 | func Swipe2(x1, y1, x2, y2, duration int) { 58 | java.Send(fmt.Sprintf("s2|%d|%d|%d|%d|%d", x1, y1, x2, y2, duration)) 59 | } 60 | 61 | func Home() { 62 | KeyAction(KEYCODE_HOME) 63 | } 64 | 65 | func Back() { 66 | KeyAction(KEYCODE_BACK) 67 | } 68 | 69 | func Recents() { 70 | KeyAction(KEYCODE_APP_SWITCH) 71 | } 72 | 73 | func PowerDialog() { 74 | shell("input keyevent --longpress KEYCODE_POWER") 75 | } 76 | 77 | func Notifications() { 78 | KeyAction(KEYCODE_NOTIFICATION) 79 | } 80 | 81 | func QuickSettings() { 82 | shell("cmd statusbar expand-settings") 83 | } 84 | 85 | func VolumeUp() { 86 | KeyAction(KEYCODE_VOLUME_UP) 87 | } 88 | 89 | func VolumeDown() { 90 | KeyAction(KEYCODE_VOLUME_DOWN) 91 | } 92 | 93 | func Camera() { 94 | KeyAction(KEYCODE_CAMERA) 95 | } 96 | 97 | func KeyAction(code int) { 98 | java.Send(fmt.Sprintf("k|%d", code)) 99 | } 100 | 101 | func random(min, max int) int { 102 | r := rand.New(rand.NewSource(time.Now().UnixNano())) 103 | return r.Intn(max-min+1) + min 104 | } 105 | 106 | func sleep(i int) { 107 | time.Sleep(time.Duration(i) * time.Millisecond) 108 | } 109 | 110 | func shell(cmd string) { 111 | if strings.Contains(cmd, ";") { 112 | cmd = "(" + cmd + ")" 113 | } 114 | cCmd := C.CString(cmd + " > /dev/null 2>&1") 115 | defer C.free(unsafe.Pointer(cCmd)) 116 | C.system(cCmd) 117 | } 118 | -------------------------------------------------------------------------------- /opencv/cgo.go: -------------------------------------------------------------------------------- 1 | package opencv 2 | 3 | /* 4 | #cgo arm64 LDFLAGS: -L../../resources/libs/arm64-v8a -lopencv_core -lopencv_imgproc 5 | #cgo amd64 LDFLAGS: -L../../resources/libs/x86_64 -lopencv_core -lopencv_imgproc 6 | #cgo 386 LDFLAGS: -L../../resources/libs/x86 -lopencv_core -lopencv_imgproc 7 | */ 8 | import "C" 9 | -------------------------------------------------------------------------------- /opencv/core_string.go: -------------------------------------------------------------------------------- 1 | package opencv 2 | 3 | func (c MatType) String() string { 4 | switch c { 5 | case MatTypeCV8U: 6 | return "CV8U" 7 | case MatTypeCV8UC2: 8 | return "CV8UC2" 9 | case MatTypeCV8UC3: 10 | return "CV8UC3" 11 | case MatTypeCV8UC4: 12 | return "CV8UC4" 13 | case MatTypeCV16U: 14 | return "CV16U" 15 | case MatTypeCV16UC2: 16 | return "CV16UC2" 17 | case MatTypeCV16UC3: 18 | return "CV16UC3" 19 | case MatTypeCV16UC4: 20 | return "CV16UC4" 21 | case MatTypeCV16S: 22 | return "CV16S" 23 | case MatTypeCV16SC2: 24 | return "CV16SC2" 25 | case MatTypeCV16SC3: 26 | return "CV16SC3" 27 | case MatTypeCV16SC4: 28 | return "CV16SC4" 29 | case MatTypeCV32S: 30 | return "CV32S" 31 | case MatTypeCV32SC2: 32 | return "CV32SC2" 33 | case MatTypeCV32SC3: 34 | return "CV32SC3" 35 | case MatTypeCV32SC4: 36 | return "CV32SC4" 37 | case MatTypeCV32F: 38 | return "CV32F" 39 | case MatTypeCV32FC2: 40 | return "CV32FC2" 41 | case MatTypeCV32FC3: 42 | return "CV32FC3" 43 | case MatTypeCV32FC4: 44 | return "CV32FC4" 45 | case MatTypeCV64F: 46 | return "CV64F" 47 | case MatTypeCV64FC2: 48 | return "CV64FC2" 49 | case MatTypeCV64FC3: 50 | return "CV64FC3" 51 | case MatTypeCV64FC4: 52 | return "CV64FC4" 53 | } 54 | return "" 55 | } 56 | 57 | func (c CompareType) String() string { 58 | switch c { 59 | case CompareEQ: 60 | return "eq" 61 | case CompareGT: 62 | return "gt" 63 | case CompareGE: 64 | return "ge" 65 | case CompareLT: 66 | return "lt" 67 | case CompareLE: 68 | return "le" 69 | case CompareNE: 70 | return "ne" 71 | } 72 | return "" 73 | } 74 | 75 | func (c CovarFlags) String() string { 76 | switch c { 77 | case CovarScrambled: 78 | return "covar-scrambled" 79 | case CovarNormal: 80 | return "covar-normal" 81 | case CovarUseAvg: 82 | return "covar-use-avg" 83 | case CovarScale: 84 | return "covar-scale" 85 | case CovarRows: 86 | return "covar-rows" 87 | case CovarCols: 88 | return "covar-cols" 89 | } 90 | return "" 91 | } 92 | 93 | func (c DftFlags) String() string { 94 | switch c { 95 | case DftForward: 96 | return "dft-forward" 97 | case DftInverse: 98 | return "dft-inverse" 99 | case DftScale: 100 | return "dft-scale" 101 | case DftRows: 102 | return "dft-rows" 103 | case DftComplexOutput: 104 | return "dft-complex-output" 105 | case DftRealOutput: 106 | return "dft-real-output" 107 | case DftComplexInput: 108 | return "dft-complex-input" 109 | } 110 | return "" 111 | } 112 | 113 | func (c RotateFlag) String() string { 114 | switch c { 115 | case Rotate90Clockwise: 116 | return "rotate-90-clockwise" 117 | case Rotate180Clockwise: 118 | return "rotate-180-clockwise" 119 | case Rotate90CounterClockwise: 120 | return "rotate-90-counter-clockwise" 121 | } 122 | return "" 123 | } 124 | 125 | func (c KMeansFlags) String() string { 126 | switch c { 127 | case KMeansRandomCenters: 128 | return "kmeans-random-centers" 129 | case KMeansPPCenters: 130 | return "kmeans-pp-centers" 131 | case KMeansUseInitialLabels: 132 | return "kmeans-use-initial-labels" 133 | } 134 | return "" 135 | } 136 | 137 | func (c NormType) String() string { 138 | switch c { 139 | case NormInf: 140 | return "norm-inf" 141 | case NormL1: 142 | return "norm-l1" 143 | case NormL2: 144 | return "norm-l2" 145 | case NormL2Sqr: 146 | return "norm-l2-sqr" 147 | case NormHamming: 148 | return "norm-hamming" 149 | case NormHamming2: 150 | return "norm-hamming2" 151 | case NormRelative: 152 | return "norm-relative" 153 | case NormMinMax: 154 | return "norm-minmax" 155 | } 156 | return "" 157 | } 158 | 159 | func (c TermCriteriaType) String() string { 160 | switch c { 161 | case Count: 162 | return "count" 163 | case EPS: 164 | return "eps" 165 | } 166 | return "" 167 | } 168 | 169 | func (c SolveDecompositionFlags) String() string { 170 | switch c { 171 | case SolveDecompositionLu: 172 | return "solve-decomposition-lu" 173 | case SolveDecompositionSvd: 174 | return "solve-decomposition-svd" 175 | case SolveDecompositionEing: 176 | return "solve-decomposition-eing" 177 | case SolveDecompositionCholesky: 178 | return "solve-decomposition-cholesky" 179 | case SolveDecompositionQr: 180 | return "solve-decomposition-qr" 181 | case SolveDecompositionNormal: 182 | return "solve-decomposition-normal" 183 | } 184 | return "" 185 | } 186 | 187 | func (c ReduceTypes) String() string { 188 | switch c { 189 | case ReduceSum: 190 | return "reduce-sum" 191 | case ReduceAvg: 192 | return "reduce-avg" 193 | case ReduceMax: 194 | return "reduce-max" 195 | case ReduceMin: 196 | return "reduce-min" 197 | } 198 | return "" 199 | } 200 | 201 | func (c SortFlags) String() string { 202 | switch c { 203 | case SortEveryRow: 204 | return "sort-every-row" 205 | case SortEveryColumn: 206 | return "sort-every-column" 207 | case SortDescending: 208 | return "sort-descending" 209 | } 210 | return "" 211 | } 212 | -------------------------------------------------------------------------------- /opencv/mat_noprofile.go: -------------------------------------------------------------------------------- 1 | //go:build !matprofile 2 | // +build !matprofile 3 | 4 | package opencv 5 | 6 | /* 7 | #include 8 | #include "core.h" 9 | */ 10 | import "C" 11 | 12 | // addMatToProfile does nothing if matprofile tag is not set. 13 | func addMatToProfile(p C.Mat) { 14 | return 15 | } 16 | 17 | // newMat returns a new Mat from a C Mat 18 | func newMat(p C.Mat) Mat { 19 | return Mat{p: p} 20 | } 21 | 22 | // Close the Mat object. 23 | func (m *Mat) Close() error { 24 | C.Mat_Close(m.p) 25 | m.p = nil 26 | m.d = nil 27 | return nil 28 | } 29 | -------------------------------------------------------------------------------- /opencv/opencv.go: -------------------------------------------------------------------------------- 1 | package opencv 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "image" 7 | "image/color" 8 | "math" 9 | 10 | "github.com/Dasongzi1366/AutoGo/images" 11 | ) 12 | 13 | var templateMap = make(map[string]Mat) 14 | var maskMap = make(map[string]Mat) 15 | 16 | // FindImage 在指定区域内查找匹配的图片模板,支持透明图像处理。 17 | // 18 | // 参数: 19 | // - x1, y1: 区域左上角的坐标。 20 | // - x2, y2: 区域右下角的坐标。当 x2 或 y2 为 0 时,表示使用图像的最大宽度或高度。 21 | // - template: 模板图片的字节数组指针,表示要在区域内查找的图片。 22 | // - isGray: 布尔值,指示是否将图像转换为灰度图进行匹配,提升匹配速度和鲁棒性。 23 | // - scalingFactor: 缩放比例,应用于模板图片和截取的待匹配区域,确保模板能够适应不同分辨率的图像。 24 | // - 0.5 表示缩小为原图的 50%。 25 | // - 2.0 表示放大为原图的 200%。 26 | // - sim: 相似度阈值,取值范围为 0.1 到 1.0,值越高表示匹配要求越精确。 27 | // 28 | // 返回值: 29 | // - (int, int): 返回找到的图片左上角坐标。如果未找到则返回 (-1, -1)。 30 | // 31 | // 透明图支持: 32 | // - 当模板图片为透明图时,函数会自动生成遮罩来忽略透明区域。 33 | // - 透明图的判定标准:图像的四个角颜色相同,且透明像素数量占总像素数的 30% 到 99%。 34 | // 35 | // 缩放说明: 36 | // - scalingFactor 控制模板和待匹配区域的缩放比例,通过对模板图像的缩放,实现在不同分辨率的屏幕上进行一致的匹配。 37 | // - 当模板图像在原分辨率(例如 540x960)下创建,但需要在更高或更低分辨率(例如 1080x1920 或 270x480)上查找时, 38 | // 通过调整 scalingFactor 使模板与不同分辨率的目标图像比例一致。 39 | // - 例如:scalingFactor 为 2.0 时,模板会放大 200%,适用于将 540x960 的模板匹配到 1080x1920 的图像中。 40 | // scalingFactor 为 0.5 时,模板会缩小 50%,适用于将 540x960 的模板匹配到 270x480 的图像中。 41 | // - 若 scalingFactor 为 1.0,则模板和截取区域保持原尺寸,不进行缩放。 42 | func FindImage(x1, y1, x2, y2 int, template *[]byte, isGray bool, scalingFactor, sim float32) (int, int) { 43 | if scalingFactor < 0.1 { 44 | scalingFactor = 1 45 | } 46 | mat2, mat3 := byte2mat(template, isGray, scalingFactor) 47 | if mat2.Empty() { 48 | return -1, -1 49 | } 50 | 51 | img := images.CaptureScreen(x1, y1, x2, y2) 52 | if img == nil { 53 | return -1, -1 54 | } 55 | 56 | bounds := img.Bounds() 57 | mat1, err := NewMatFromBytes(bounds.Dy(), bounds.Dx(), MatTypeCV8UC4, img.Pix) 58 | defer mat1.Close() 59 | if err != nil { 60 | return -1, -1 61 | } 62 | 63 | if isGray { 64 | mat1 = matGray(mat1) 65 | } 66 | 67 | result := NewMat() 68 | defer result.Close() 69 | 70 | MatchTemplate(mat1, mat2, &result, TmCcoeffNormed, mat3) 71 | 72 | _, maxVal, _, maxLoc := MinMaxLoc(result) 73 | if maxVal >= 0.5+sim*0.5 { 74 | return int(float32(maxLoc.X)/scalingFactor) + x1, int(float32(maxLoc.Y)/scalingFactor) + y1 75 | } 76 | 77 | return -1, -1 78 | } 79 | 80 | func byte2mat(pngData *[]byte, isGray bool, scale float32) (Mat, Mat) { 81 | sign := fmt.Sprintf("%p-%t-%.2f", pngData, isGray, scale) 82 | 83 | if cachedMat, ok := templateMap[sign]; ok { 84 | return cachedMat, maskMap[sign] 85 | } 86 | 87 | img, _, err := image.Decode(bytes.NewReader(*pngData)) 88 | if err != nil { 89 | fmt.Println("图像解码失败") 90 | return NewMat(), NewMat() 91 | } 92 | imgNrgba := images.ImageToNRGBA(img) 93 | 94 | bounds := imgNrgba.Bounds() 95 | templateMat, _ := NewMatFromBytes(bounds.Dy(), bounds.Dx(), MatTypeCV8UC4, imgNrgba.Pix) 96 | 97 | isTransparent := checkTransparent(imgNrgba) 98 | 99 | if isGray { 100 | templateMat = matGray(templateMat) 101 | } 102 | templateMat = matScale(templateMat, scale) 103 | 104 | var maskMat Mat 105 | if isTransparent { 106 | maskMat = createMask(imgNrgba) 107 | } else { 108 | maskMat = NewMat() 109 | } 110 | 111 | templateMap[sign] = templateMat 112 | maskMap[sign] = maskMat 113 | 114 | return templateMap[sign], maskMap[sign] 115 | } 116 | 117 | func matGray(mat Mat) Mat { 118 | grayMat := NewMat() 119 | CvtColor(mat, &grayMat, ColorBGRToGray) 120 | _ = mat.Close() 121 | return grayMat 122 | } 123 | 124 | func matScale(mat Mat, scale float32) Mat { 125 | const epsilon = 1e-6 126 | if math.Abs(float64(scale-1)) < epsilon { 127 | return mat 128 | } 129 | scaledMat := NewMat() 130 | Resize(mat, &scaledMat, image.Point{X: int(float32(mat.Cols()) * scale), Y: int(float32(mat.Rows()) * scale)}, 0, 0, InterpolationLinear) 131 | _ = mat.Close() 132 | return scaledMat 133 | } 134 | 135 | // 判断是否是透明图 136 | func checkTransparent(img image.Image) bool { 137 | width := img.Bounds().Dx() 138 | height := img.Bounds().Dy() 139 | 140 | if width < 2 || height < 2 { 141 | return false 142 | } 143 | 144 | c0 := getRGB(img.At(0, 0)) 145 | c1 := getRGB(img.At(width-1, 0)) 146 | c2 := getRGB(img.At(0, height-1)) 147 | c3 := getRGB(img.At(width-1, height-1)) 148 | 149 | if c0 != c1 || c0 != c2 || c0 != c3 { 150 | return false 151 | } 152 | 153 | transparentCount := 0 154 | totalPixels := width * height 155 | for y := 0; y < height; y++ { 156 | for x := 0; x < width; x++ { 157 | if getRGB(img.At(x, y)) == c0 { 158 | transparentCount++ 159 | } 160 | } 161 | } 162 | 163 | if transparentCount >= int(float32(totalPixels)*0.3) && transparentCount < totalPixels { 164 | return true 165 | } 166 | 167 | return false 168 | } 169 | 170 | // 创建透明图遮罩 171 | func createMask(img image.Image) Mat { 172 | width := img.Bounds().Dx() 173 | height := img.Bounds().Dy() 174 | 175 | c0 := getRGB(img.At(0, 0)) 176 | 177 | mask := NewMatWithSize(height, width, MatTypeCV8U) 178 | 179 | for y := 0; y < height; y++ { 180 | for x := 0; x < width; x++ { 181 | if getRGB(img.At(x, y)) == c0 { 182 | mask.SetUCharAt(y, x, 1) 183 | } else { 184 | mask.SetUCharAt(y, x, 0) 185 | } 186 | } 187 | } 188 | 189 | return mask 190 | } 191 | 192 | func getRGB(c color.Color) color.RGBA { 193 | r, g, b, _ := c.RGBA() // 忽略 Alpha 通道 194 | return color.RGBA{uint8(r >> 8), uint8(g >> 8), uint8(b >> 8), 255} 195 | } 196 | -------------------------------------------------------------------------------- /opencv/opencv2/core/async.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_ASYNC_HPP 6 | #define OPENCV_CORE_ASYNC_HPP 7 | 8 | #include 9 | 10 | //#include 11 | #include 12 | 13 | namespace cv { 14 | 15 | /** @addtogroup core_async 16 | 17 | @{ 18 | */ 19 | 20 | 21 | /** @brief Returns result of asynchronous operations 22 | 23 | Object has attached asynchronous state. 24 | Assignment operator doesn't clone asynchronous state (it is shared between all instances). 25 | 26 | Result can be fetched via get() method only once. 27 | 28 | */ 29 | class CV_EXPORTS_W AsyncArray 30 | { 31 | public: 32 | ~AsyncArray() CV_NOEXCEPT; 33 | CV_WRAP AsyncArray() CV_NOEXCEPT; 34 | AsyncArray(const AsyncArray& o) CV_NOEXCEPT; 35 | AsyncArray& operator=(const AsyncArray& o) CV_NOEXCEPT; 36 | CV_WRAP void release() CV_NOEXCEPT; 37 | 38 | /** Fetch the result. 39 | @param[out] dst destination array 40 | 41 | Waits for result until container has valid result. 42 | Throws exception if exception was stored as a result. 43 | 44 | Throws exception on invalid container state. 45 | 46 | @note Result or stored exception can be fetched only once. 47 | */ 48 | CV_WRAP void get(OutputArray dst) const; 49 | 50 | /** Retrieving the result with timeout 51 | @param[out] dst destination array 52 | @param[in] timeoutNs timeout in nanoseconds, -1 for infinite wait 53 | 54 | @returns true if result is ready, false if the timeout has expired 55 | 56 | @note Result or stored exception can be fetched only once. 57 | */ 58 | bool get(OutputArray dst, int64 timeoutNs) const; 59 | 60 | CV_WRAP inline 61 | bool get(OutputArray dst, double timeoutNs) const { return get(dst, (int64)timeoutNs); } 62 | 63 | bool wait_for(int64 timeoutNs) const; 64 | 65 | CV_WRAP inline 66 | bool wait_for(double timeoutNs) const { return wait_for((int64)timeoutNs); } 67 | 68 | CV_WRAP bool valid() const CV_NOEXCEPT; 69 | 70 | inline AsyncArray(AsyncArray&& o) { p = o.p; o.p = NULL; } 71 | inline AsyncArray& operator=(AsyncArray&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; } 72 | 73 | template 74 | inline bool get(OutputArray dst, const std::chrono::duration<_Rep, _Period>& timeout) 75 | { 76 | return get(dst, (int64)(std::chrono::nanoseconds(timeout).count())); 77 | } 78 | 79 | template 80 | inline bool wait_for(const std::chrono::duration<_Rep, _Period>& timeout) 81 | { 82 | return wait_for((int64)(std::chrono::nanoseconds(timeout).count())); 83 | } 84 | 85 | #if 0 86 | std::future getFutureMat() const; 87 | std::future getFutureUMat() const; 88 | #endif 89 | 90 | 91 | // PImpl 92 | struct Impl; friend struct Impl; 93 | inline void* _getImpl() const CV_NOEXCEPT { return p; } 94 | protected: 95 | Impl* p; 96 | }; 97 | 98 | 99 | //! @} 100 | } // namespace 101 | #endif // OPENCV_CORE_ASYNC_HPP 102 | -------------------------------------------------------------------------------- /opencv/opencv2/core/bufferpool.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | // 5 | // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. 6 | 7 | #ifndef OPENCV_CORE_BUFFER_POOL_HPP 8 | #define OPENCV_CORE_BUFFER_POOL_HPP 9 | 10 | #ifdef _MSC_VER 11 | #pragma warning(push) 12 | #pragma warning(disable: 4265) 13 | #endif 14 | 15 | namespace cv 16 | { 17 | 18 | //! @addtogroup core 19 | //! @{ 20 | 21 | class BufferPoolController 22 | { 23 | protected: 24 | ~BufferPoolController() { } 25 | public: 26 | virtual size_t getReservedSize() const = 0; 27 | virtual size_t getMaxReservedSize() const = 0; 28 | virtual void setMaxReservedSize(size_t size) = 0; 29 | virtual void freeAllReservedBuffers() = 0; 30 | }; 31 | 32 | //! @} 33 | 34 | } 35 | 36 | #ifdef _MSC_VER 37 | #pragma warning(pop) 38 | #endif 39 | 40 | #endif // OPENCV_CORE_BUFFER_POOL_HPP 41 | -------------------------------------------------------------------------------- /opencv/opencv2/core/core.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 | // Third party copyrights are property of their respective owners. 17 | // 18 | // Redistribution and use in source and binary forms, with or without modification, 19 | // are permitted provided that the following conditions are met: 20 | // 21 | // * Redistribution's of source code must retain the above copyright notice, 22 | // this list of conditions and the following disclaimer. 23 | // 24 | // * Redistribution's in binary form must reproduce the above copyright notice, 25 | // this list of conditions and the following disclaimer in the documentation 26 | // and/or other materials provided with the distribution. 27 | // 28 | // * The name of the copyright holders may not be used to endorse or promote products 29 | // derived from this software without specific prior written permission. 30 | // 31 | // This software is provided by the copyright holders and contributors "as is" and 32 | // any express or implied warranties, including, but not limited to, the implied 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, 35 | // indirect, incidental, special, exemplary, or consequential damages 36 | // (including, but not limited to, procurement of substitute goods or services; 37 | // loss of use, data, or profits; or business interruption) however caused 38 | // and on any theory of liability, whether in contract, strict liability, 39 | // or tort (including negligence or otherwise) arising in any way out of 40 | // the use of this software, even if advised of the possibility of such damage. 41 | // 42 | //M*/ 43 | 44 | #ifdef __OPENCV_BUILD 45 | #error this is a compatibility header which should not be used inside the OpenCV library 46 | #endif 47 | 48 | #include "opencv2/core.hpp" 49 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/common.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_COMMON_HPP 44 | #define OPENCV_CUDA_COMMON_HPP 45 | 46 | #include 47 | #include "opencv2/core/cuda_types.hpp" 48 | #include "opencv2/core/cvdef.h" 49 | #include "opencv2/core/base.hpp" 50 | 51 | /** @file 52 | * @deprecated Use @ref cudev instead. 53 | */ 54 | 55 | //! @cond IGNORED 56 | 57 | #ifndef CV_PI_F 58 | #ifndef CV_PI 59 | #define CV_PI_F 3.14159265f 60 | #else 61 | #define CV_PI_F ((float)CV_PI) 62 | #endif 63 | #endif 64 | 65 | namespace cv { namespace cuda { 66 | static inline void checkCudaError(cudaError_t err, const char* file, const int line, const char* func) 67 | { 68 | if (cudaSuccess != err) { 69 | cudaGetLastError(); // reset the last stored error to cudaSuccess 70 | cv::error(cv::Error::GpuApiCallError, cudaGetErrorString(err), func, file, line); 71 | } 72 | } 73 | }} 74 | 75 | #ifndef cudaSafeCall 76 | #define cudaSafeCall(expr) cv::cuda::checkCudaError(expr, __FILE__, __LINE__, CV_Func) 77 | #endif 78 | 79 | namespace cv { namespace cuda 80 | { 81 | template static inline bool isAligned(const T* ptr, size_t size) 82 | { 83 | return reinterpret_cast(ptr) % size == 0; 84 | } 85 | 86 | static inline bool isAligned(size_t step, size_t size) 87 | { 88 | return step % size == 0; 89 | } 90 | }} 91 | 92 | namespace cv { namespace cuda 93 | { 94 | namespace device 95 | { 96 | __host__ __device__ __forceinline__ int divUp(int total, int grain) 97 | { 98 | return (total + grain - 1) / grain; 99 | } 100 | 101 | #if (CUDART_VERSION >= 12000) 102 | template inline void createTextureObjectPitch2D(cudaTextureObject_t*, PtrStepSz&, const cudaTextureDesc&) { 103 | CV_Error(cv::Error::GpuNotSupported, "Function removed in CUDA SDK 12"); } 104 | #else 105 | //TODO: remove from OpenCV 5.x 106 | template inline void bindTexture(const textureReference* tex, const PtrStepSz& img) 107 | { 108 | cudaChannelFormatDesc desc = cudaCreateChannelDesc(); 109 | cudaSafeCall( cudaBindTexture2D(0, tex, img.ptr(), &desc, img.cols, img.rows, img.step) ); 110 | } 111 | 112 | template inline void createTextureObjectPitch2D(cudaTextureObject_t* tex, PtrStepSz& img, const cudaTextureDesc& texDesc) 113 | { 114 | cudaResourceDesc resDesc; 115 | memset(&resDesc, 0, sizeof(resDesc)); 116 | resDesc.resType = cudaResourceTypePitch2D; 117 | resDesc.res.pitch2D.devPtr = static_cast(img.ptr()); 118 | resDesc.res.pitch2D.height = img.rows; 119 | resDesc.res.pitch2D.width = img.cols; 120 | resDesc.res.pitch2D.pitchInBytes = img.step; 121 | resDesc.res.pitch2D.desc = cudaCreateChannelDesc(); 122 | 123 | cudaSafeCall( cudaCreateTextureObject(tex, &resDesc, &texDesc, NULL) ); 124 | } 125 | #endif 126 | } 127 | }} 128 | 129 | //! @endcond 130 | 131 | #endif // OPENCV_CUDA_COMMON_HPP 132 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/datamov_utils.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_DATAMOV_UTILS_HPP 44 | #define OPENCV_CUDA_DATAMOV_UTILS_HPP 45 | 46 | #include "common.hpp" 47 | 48 | /** @file 49 | * @deprecated Use @ref cudev instead. 50 | */ 51 | 52 | //! @cond IGNORED 53 | 54 | namespace cv { namespace cuda { namespace device 55 | { 56 | #if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 200 57 | 58 | // for Fermi memory space is detected automatically 59 | template struct ForceGlob 60 | { 61 | __device__ __forceinline__ static void Load(const T* ptr, int offset, T& val) { val = ptr[offset]; } 62 | }; 63 | 64 | #else // __CUDA_ARCH__ >= 200 65 | 66 | #if defined(_WIN64) || defined(__LP64__) 67 | // 64-bit register modifier for inlined asm 68 | #define OPENCV_CUDA_ASM_PTR "l" 69 | #else 70 | // 32-bit register modifier for inlined asm 71 | #define OPENCV_CUDA_ASM_PTR "r" 72 | #endif 73 | 74 | template struct ForceGlob; 75 | 76 | #define OPENCV_CUDA_DEFINE_FORCE_GLOB(base_type, ptx_type, reg_mod) \ 77 | template <> struct ForceGlob \ 78 | { \ 79 | __device__ __forceinline__ static void Load(const base_type* ptr, int offset, base_type& val) \ 80 | { \ 81 | asm("ld.global."#ptx_type" %0, [%1];" : "="#reg_mod(val) : OPENCV_CUDA_ASM_PTR(ptr + offset)); \ 82 | } \ 83 | }; 84 | 85 | #define OPENCV_CUDA_DEFINE_FORCE_GLOB_B(base_type, ptx_type) \ 86 | template <> struct ForceGlob \ 87 | { \ 88 | __device__ __forceinline__ static void Load(const base_type* ptr, int offset, base_type& val) \ 89 | { \ 90 | asm("ld.global."#ptx_type" %0, [%1];" : "=r"(*reinterpret_cast(&val)) : OPENCV_CUDA_ASM_PTR(ptr + offset)); \ 91 | } \ 92 | }; 93 | 94 | OPENCV_CUDA_DEFINE_FORCE_GLOB_B(uchar, u8) 95 | OPENCV_CUDA_DEFINE_FORCE_GLOB_B(schar, s8) 96 | OPENCV_CUDA_DEFINE_FORCE_GLOB_B(char, b8) 97 | OPENCV_CUDA_DEFINE_FORCE_GLOB (ushort, u16, h) 98 | OPENCV_CUDA_DEFINE_FORCE_GLOB (short, s16, h) 99 | OPENCV_CUDA_DEFINE_FORCE_GLOB (uint, u32, r) 100 | OPENCV_CUDA_DEFINE_FORCE_GLOB (int, s32, r) 101 | OPENCV_CUDA_DEFINE_FORCE_GLOB (float, f32, f) 102 | OPENCV_CUDA_DEFINE_FORCE_GLOB (double, f64, d) 103 | 104 | #undef OPENCV_CUDA_DEFINE_FORCE_GLOB 105 | #undef OPENCV_CUDA_DEFINE_FORCE_GLOB_B 106 | #undef OPENCV_CUDA_ASM_PTR 107 | 108 | #endif // __CUDA_ARCH__ >= 200 109 | }}} // namespace cv { namespace cuda { namespace cudev 110 | 111 | //! @endcond 112 | 113 | #endif // OPENCV_CUDA_DATAMOV_UTILS_HPP 114 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/detail/vec_distance_detail.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP 44 | #define OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP 45 | 46 | #include "../datamov_utils.hpp" 47 | 48 | //! @cond IGNORED 49 | 50 | namespace cv { namespace cuda { namespace device 51 | { 52 | namespace vec_distance_detail 53 | { 54 | template struct UnrollVecDiffCached 55 | { 56 | template 57 | static __device__ void calcCheck(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int ind) 58 | { 59 | if (ind < len) 60 | { 61 | T1 val1 = *vecCached++; 62 | 63 | T2 val2; 64 | ForceGlob::Load(vecGlob, ind, val2); 65 | 66 | dist.reduceIter(val1, val2); 67 | 68 | UnrollVecDiffCached::calcCheck(vecCached, vecGlob, len, dist, ind + THREAD_DIM); 69 | } 70 | } 71 | 72 | template 73 | static __device__ void calcWithoutCheck(const T1* vecCached, const T2* vecGlob, Dist& dist) 74 | { 75 | T1 val1 = *vecCached++; 76 | 77 | T2 val2; 78 | ForceGlob::Load(vecGlob, 0, val2); 79 | vecGlob += THREAD_DIM; 80 | 81 | dist.reduceIter(val1, val2); 82 | 83 | UnrollVecDiffCached::calcWithoutCheck(vecCached, vecGlob, dist); 84 | } 85 | }; 86 | template struct UnrollVecDiffCached 87 | { 88 | template 89 | static __device__ __forceinline__ void calcCheck(const T1*, const T2*, int, Dist&, int) 90 | { 91 | } 92 | 93 | template 94 | static __device__ __forceinline__ void calcWithoutCheck(const T1*, const T2*, Dist&) 95 | { 96 | } 97 | }; 98 | 99 | template struct VecDiffCachedCalculator; 100 | template struct VecDiffCachedCalculator 101 | { 102 | template 103 | static __device__ __forceinline__ void calc(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int tid) 104 | { 105 | UnrollVecDiffCached::calcCheck(vecCached, vecGlob, len, dist, tid); 106 | } 107 | }; 108 | template struct VecDiffCachedCalculator 109 | { 110 | template 111 | static __device__ __forceinline__ void calc(const T1* vecCached, const T2* vecGlob, int len, Dist& dist, int tid) 112 | { 113 | UnrollVecDiffCached::calcWithoutCheck(vecCached, vecGlob + tid, dist); 114 | } 115 | }; 116 | } // namespace vec_distance_detail 117 | }}} // namespace cv { namespace cuda { namespace cudev 118 | 119 | //! @endcond 120 | 121 | #endif // OPENCV_CUDA_VEC_DISTANCE_DETAIL_HPP 122 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/dynamic_smem.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_DYNAMIC_SMEM_HPP 44 | #define OPENCV_CUDA_DYNAMIC_SMEM_HPP 45 | 46 | /** @file 47 | * @deprecated Use @ref cudev instead. 48 | */ 49 | 50 | //! @cond IGNORED 51 | 52 | namespace cv { namespace cuda { namespace device 53 | { 54 | template struct DynamicSharedMem 55 | { 56 | __device__ __forceinline__ operator T*() 57 | { 58 | extern __shared__ int __smem[]; 59 | return (T*)__smem; 60 | } 61 | 62 | __device__ __forceinline__ operator const T*() const 63 | { 64 | extern __shared__ int __smem[]; 65 | return (T*)__smem; 66 | } 67 | }; 68 | 69 | // specialize for double to avoid unaligned memory access compile errors 70 | template<> struct DynamicSharedMem 71 | { 72 | __device__ __forceinline__ operator double*() 73 | { 74 | extern __shared__ double __smem_d[]; 75 | return (double*)__smem_d; 76 | } 77 | 78 | __device__ __forceinline__ operator const double*() const 79 | { 80 | extern __shared__ double __smem_d[]; 81 | return (double*)__smem_d; 82 | } 83 | }; 84 | }}} 85 | 86 | //! @endcond 87 | 88 | #endif // OPENCV_CUDA_DYNAMIC_SMEM_HPP 89 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/funcattrib.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP 44 | #define OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP 45 | 46 | #include 47 | 48 | /** @file 49 | * @deprecated Use @ref cudev instead. 50 | */ 51 | 52 | //! @cond IGNORED 53 | 54 | namespace cv { namespace cuda { namespace device 55 | { 56 | template 57 | void printFuncAttrib(Func& func) 58 | { 59 | 60 | cudaFuncAttributes attrs; 61 | cudaFuncGetAttributes(&attrs, func); 62 | 63 | printf("=== Function stats ===\n"); 64 | printf("Name: \n"); 65 | printf("sharedSizeBytes = %d\n", attrs.sharedSizeBytes); 66 | printf("constSizeBytes = %d\n", attrs.constSizeBytes); 67 | printf("localSizeBytes = %d\n", attrs.localSizeBytes); 68 | printf("maxThreadsPerBlock = %d\n", attrs.maxThreadsPerBlock); 69 | printf("numRegs = %d\n", attrs.numRegs); 70 | printf("ptxVersion = %d\n", attrs.ptxVersion); 71 | printf("binaryVersion = %d\n", attrs.binaryVersion); 72 | printf("\n"); 73 | fflush(stdout); 74 | } 75 | }}} // namespace cv { namespace cuda { namespace cudev 76 | 77 | //! @endcond 78 | 79 | #endif /* OPENCV_CUDA_DEVICE_FUNCATTRIB_HPP */ 80 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/limits.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_LIMITS_HPP 44 | #define OPENCV_CUDA_LIMITS_HPP 45 | 46 | #include 47 | #include 48 | #include "common.hpp" 49 | 50 | /** @file 51 | * @deprecated Use @ref cudev instead. 52 | */ 53 | 54 | //! @cond IGNORED 55 | 56 | namespace cv { namespace cuda { namespace device 57 | { 58 | template struct numeric_limits; 59 | 60 | template <> struct numeric_limits 61 | { 62 | __device__ __forceinline__ static bool min() { return false; } 63 | __device__ __forceinline__ static bool max() { return true; } 64 | static const bool is_signed = false; 65 | }; 66 | 67 | template <> struct numeric_limits 68 | { 69 | __device__ __forceinline__ static signed char min() { return SCHAR_MIN; } 70 | __device__ __forceinline__ static signed char max() { return SCHAR_MAX; } 71 | static const bool is_signed = true; 72 | }; 73 | 74 | template <> struct numeric_limits 75 | { 76 | __device__ __forceinline__ static unsigned char min() { return 0; } 77 | __device__ __forceinline__ static unsigned char max() { return UCHAR_MAX; } 78 | static const bool is_signed = false; 79 | }; 80 | 81 | template <> struct numeric_limits 82 | { 83 | __device__ __forceinline__ static short min() { return SHRT_MIN; } 84 | __device__ __forceinline__ static short max() { return SHRT_MAX; } 85 | static const bool is_signed = true; 86 | }; 87 | 88 | template <> struct numeric_limits 89 | { 90 | __device__ __forceinline__ static unsigned short min() { return 0; } 91 | __device__ __forceinline__ static unsigned short max() { return USHRT_MAX; } 92 | static const bool is_signed = false; 93 | }; 94 | 95 | template <> struct numeric_limits 96 | { 97 | __device__ __forceinline__ static int min() { return INT_MIN; } 98 | __device__ __forceinline__ static int max() { return INT_MAX; } 99 | static const bool is_signed = true; 100 | }; 101 | 102 | template <> struct numeric_limits 103 | { 104 | __device__ __forceinline__ static unsigned int min() { return 0; } 105 | __device__ __forceinline__ static unsigned int max() { return UINT_MAX; } 106 | static const bool is_signed = false; 107 | }; 108 | 109 | template <> struct numeric_limits 110 | { 111 | __device__ __forceinline__ static float min() { return FLT_MIN; } 112 | __device__ __forceinline__ static float max() { return FLT_MAX; } 113 | __device__ __forceinline__ static float epsilon() { return FLT_EPSILON; } 114 | static const bool is_signed = true; 115 | }; 116 | 117 | template <> struct numeric_limits 118 | { 119 | __device__ __forceinline__ static double min() { return DBL_MIN; } 120 | __device__ __forceinline__ static double max() { return DBL_MAX; } 121 | __device__ __forceinline__ static double epsilon() { return DBL_EPSILON; } 122 | static const bool is_signed = true; 123 | }; 124 | }}} // namespace cv { namespace cuda { namespace cudev { 125 | 126 | //! @endcond 127 | 128 | #endif // OPENCV_CUDA_LIMITS_HPP 129 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/transform.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_TRANSFORM_HPP 44 | #define OPENCV_CUDA_TRANSFORM_HPP 45 | 46 | #include "common.hpp" 47 | #include "utility.hpp" 48 | #include "detail/transform_detail.hpp" 49 | 50 | /** @file 51 | * @deprecated Use @ref cudev instead. 52 | */ 53 | 54 | //! @cond IGNORED 55 | 56 | namespace cv { namespace cuda { namespace device 57 | { 58 | template 59 | static inline void transform(PtrStepSz src, PtrStepSz dst, UnOp op, const Mask& mask, cudaStream_t stream) 60 | { 61 | typedef TransformFunctorTraits ft; 62 | transform_detail::TransformDispatcher::cn == 1 && VecTraits::cn == 1 && ft::smart_shift != 1>::call(src, dst, op, mask, stream); 63 | } 64 | 65 | template 66 | static inline void transform(PtrStepSz src1, PtrStepSz src2, PtrStepSz dst, BinOp op, const Mask& mask, cudaStream_t stream) 67 | { 68 | typedef TransformFunctorTraits ft; 69 | transform_detail::TransformDispatcher::cn == 1 && VecTraits::cn == 1 && VecTraits::cn == 1 && ft::smart_shift != 1>::call(src1, src2, dst, op, mask, stream); 70 | } 71 | }}} 72 | 73 | //! @endcond 74 | 75 | #endif // OPENCV_CUDA_TRANSFORM_HPP 76 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/type_traits.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_TYPE_TRAITS_HPP 44 | #define OPENCV_CUDA_TYPE_TRAITS_HPP 45 | 46 | #include "detail/type_traits_detail.hpp" 47 | 48 | /** @file 49 | * @deprecated Use @ref cudev instead. 50 | */ 51 | 52 | //! @cond IGNORED 53 | 54 | namespace cv { namespace cuda { namespace device 55 | { 56 | template struct IsSimpleParameter 57 | { 58 | enum {value = type_traits_detail::IsIntegral::value || type_traits_detail::IsFloat::value || 59 | type_traits_detail::PointerTraits::type>::value}; 60 | }; 61 | 62 | template struct TypeTraits 63 | { 64 | typedef typename type_traits_detail::UnConst::type NonConstType; 65 | typedef typename type_traits_detail::UnVolatile::type NonVolatileType; 66 | typedef typename type_traits_detail::UnVolatile::type>::type UnqualifiedType; 67 | typedef typename type_traits_detail::PointerTraits::type PointeeType; 68 | typedef typename type_traits_detail::ReferenceTraits::type ReferredType; 69 | 70 | enum { isConst = type_traits_detail::UnConst::value }; 71 | enum { isVolatile = type_traits_detail::UnVolatile::value }; 72 | 73 | enum { isReference = type_traits_detail::ReferenceTraits::value }; 74 | enum { isPointer = type_traits_detail::PointerTraits::type>::value }; 75 | 76 | enum { isUnsignedInt = type_traits_detail::IsUnsignedIntegral::value }; 77 | enum { isSignedInt = type_traits_detail::IsSignedIntergral::value }; 78 | enum { isIntegral = type_traits_detail::IsIntegral::value }; 79 | enum { isFloat = type_traits_detail::IsFloat::value }; 80 | enum { isArith = isIntegral || isFloat }; 81 | enum { isVec = type_traits_detail::IsVec::value }; 82 | 83 | typedef typename type_traits_detail::Select::value, 84 | T, typename type_traits_detail::AddParameterType::type>::type ParameterType; 85 | }; 86 | }}} 87 | 88 | //! @endcond 89 | 90 | #endif // OPENCV_CUDA_TYPE_TRAITS_HPP 91 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/warp.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_DEVICE_WARP_HPP 44 | #define OPENCV_CUDA_DEVICE_WARP_HPP 45 | 46 | /** @file 47 | * @deprecated Use @ref cudev instead. 48 | */ 49 | 50 | //! @cond IGNORED 51 | 52 | namespace cv { namespace cuda { namespace device 53 | { 54 | struct Warp 55 | { 56 | enum 57 | { 58 | LOG_WARP_SIZE = 5, 59 | WARP_SIZE = 1 << LOG_WARP_SIZE, 60 | STRIDE = WARP_SIZE 61 | }; 62 | 63 | /** \brief Returns the warp lane ID of the calling thread. */ 64 | static __device__ __forceinline__ unsigned int laneId() 65 | { 66 | unsigned int ret; 67 | asm("mov.u32 %0, %%laneid;" : "=r"(ret) ); 68 | return ret; 69 | } 70 | 71 | template 72 | static __device__ __forceinline__ void fill(It beg, It end, const T& value) 73 | { 74 | for(It t = beg + laneId(); t < end; t += STRIDE) 75 | *t = value; 76 | } 77 | 78 | template 79 | static __device__ __forceinline__ OutIt copy(InIt beg, InIt end, OutIt out) 80 | { 81 | for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE) 82 | *out = *t; 83 | return out; 84 | } 85 | 86 | template 87 | static __device__ __forceinline__ OutIt transform(InIt beg, InIt end, OutIt out, UnOp op) 88 | { 89 | for(InIt t = beg + laneId(); t < end; t += STRIDE, out += STRIDE) 90 | *out = op(*t); 91 | return out; 92 | } 93 | 94 | template 95 | static __device__ __forceinline__ OutIt transform(InIt1 beg1, InIt1 end1, InIt2 beg2, OutIt out, BinOp op) 96 | { 97 | unsigned int lane = laneId(); 98 | 99 | InIt1 t1 = beg1 + lane; 100 | InIt2 t2 = beg2 + lane; 101 | for(; t1 < end1; t1 += STRIDE, t2 += STRIDE, out += STRIDE) 102 | *out = op(*t1, *t2); 103 | return out; 104 | } 105 | 106 | template 107 | static __device__ __forceinline__ T reduce(volatile T *ptr, BinOp op) 108 | { 109 | const unsigned int lane = laneId(); 110 | 111 | if (lane < 16) 112 | { 113 | T partial = ptr[lane]; 114 | 115 | ptr[lane] = partial = op(partial, ptr[lane + 16]); 116 | ptr[lane] = partial = op(partial, ptr[lane + 8]); 117 | ptr[lane] = partial = op(partial, ptr[lane + 4]); 118 | ptr[lane] = partial = op(partial, ptr[lane + 2]); 119 | ptr[lane] = partial = op(partial, ptr[lane + 1]); 120 | } 121 | 122 | return *ptr; 123 | } 124 | 125 | template 126 | static __device__ __forceinline__ void yota(OutIt beg, OutIt end, T value) 127 | { 128 | unsigned int lane = laneId(); 129 | value += lane; 130 | 131 | for(OutIt t = beg + lane; t < end; t += STRIDE, value += STRIDE) 132 | *t = value; 133 | } 134 | }; 135 | }}} // namespace cv { namespace cuda { namespace cudev 136 | 137 | //! @endcond 138 | 139 | #endif /* OPENCV_CUDA_DEVICE_WARP_HPP */ 140 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda/warp_reduce.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CUDA_WARP_REDUCE_HPP__ 44 | #define OPENCV_CUDA_WARP_REDUCE_HPP__ 45 | 46 | /** @file 47 | * @deprecated Use @ref cudev instead. 48 | */ 49 | 50 | //! @cond IGNORED 51 | 52 | namespace cv { namespace cuda { namespace device 53 | { 54 | template 55 | __device__ __forceinline__ T warp_reduce(volatile T *ptr , const unsigned int tid = threadIdx.x) 56 | { 57 | const unsigned int lane = tid & 31; // index of thread in warp (0..31) 58 | 59 | if (lane < 16) 60 | { 61 | T partial = ptr[tid]; 62 | 63 | ptr[tid] = partial = partial + ptr[tid + 16]; 64 | ptr[tid] = partial = partial + ptr[tid + 8]; 65 | ptr[tid] = partial = partial + ptr[tid + 4]; 66 | ptr[tid] = partial = partial + ptr[tid + 2]; 67 | ptr[tid] = partial = partial + ptr[tid + 1]; 68 | } 69 | 70 | return ptr[tid - lane]; 71 | } 72 | }}} // namespace cv { namespace cuda { namespace cudev { 73 | 74 | //! @endcond 75 | 76 | #endif /* OPENCV_CUDA_WARP_REDUCE_HPP__ */ 77 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda_stream_accessor.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP 44 | #define OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP 45 | 46 | #ifndef __cplusplus 47 | # error cuda_stream_accessor.hpp header must be compiled as C++ 48 | #endif 49 | 50 | /** @file cuda_stream_accessor.hpp 51 | * This is only header file that depends on CUDA Runtime API. All other headers are independent. 52 | */ 53 | 54 | #include 55 | #include "opencv2/core/cuda.hpp" 56 | 57 | namespace cv 58 | { 59 | namespace cuda 60 | { 61 | 62 | //! @addtogroup cudacore_struct 63 | //! @{ 64 | 65 | /** @brief Class that enables getting cudaStream_t from cuda::Stream 66 | */ 67 | struct StreamAccessor 68 | { 69 | CV_EXPORTS static cudaStream_t getStream(const Stream& stream); 70 | CV_EXPORTS static Stream wrapStream(cudaStream_t stream); 71 | }; 72 | 73 | /** @brief Class that enables getting cudaEvent_t from cuda::Event 74 | */ 75 | struct EventAccessor 76 | { 77 | CV_EXPORTS static cudaEvent_t getEvent(const Event& event); 78 | CV_EXPORTS static Event wrapEvent(cudaEvent_t event); 79 | }; 80 | 81 | //! @} 82 | 83 | } 84 | } 85 | 86 | #endif /* OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP */ 87 | -------------------------------------------------------------------------------- /opencv/opencv2/core/cuda_types.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_CORE_CUDA_TYPES_HPP 44 | #define OPENCV_CORE_CUDA_TYPES_HPP 45 | 46 | #ifndef __cplusplus 47 | # error cuda_types.hpp header must be compiled as C++ 48 | #endif 49 | 50 | #if defined(__OPENCV_BUILD) && defined(__clang__) 51 | #pragma clang diagnostic ignored "-Winconsistent-missing-override" 52 | #endif 53 | #if defined(__OPENCV_BUILD) && defined(__GNUC__) && __GNUC__ >= 5 54 | #pragma GCC diagnostic ignored "-Wsuggest-override" 55 | #endif 56 | 57 | /** @file 58 | * @deprecated Use @ref cudev instead. 59 | */ 60 | 61 | //! @cond IGNORED 62 | 63 | #ifdef __CUDACC__ 64 | #define __CV_CUDA_HOST_DEVICE__ __host__ __device__ __forceinline__ 65 | #else 66 | #define __CV_CUDA_HOST_DEVICE__ 67 | #endif 68 | 69 | namespace cv 70 | { 71 | namespace cuda 72 | { 73 | 74 | // Simple lightweight structures that encapsulates information about an image on device. 75 | // It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile 76 | 77 | template struct DevPtr 78 | { 79 | typedef T elem_type; 80 | typedef int index_type; 81 | 82 | enum { elem_size = sizeof(elem_type) }; 83 | 84 | T* data; 85 | 86 | __CV_CUDA_HOST_DEVICE__ DevPtr() : data(0) {} 87 | __CV_CUDA_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {} 88 | 89 | __CV_CUDA_HOST_DEVICE__ size_t elemSize() const { return elem_size; } 90 | __CV_CUDA_HOST_DEVICE__ operator T*() { return data; } 91 | __CV_CUDA_HOST_DEVICE__ operator const T*() const { return data; } 92 | }; 93 | 94 | template struct PtrSz : public DevPtr 95 | { 96 | __CV_CUDA_HOST_DEVICE__ PtrSz() : size(0) {} 97 | __CV_CUDA_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr(data_), size(size_) {} 98 | 99 | size_t size; 100 | }; 101 | 102 | template struct PtrStep : public DevPtr 103 | { 104 | __CV_CUDA_HOST_DEVICE__ PtrStep() : step(0) {} 105 | __CV_CUDA_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr(data_), step(step_) {} 106 | 107 | size_t step; 108 | 109 | __CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)(((DevPtr*)this)->data) + y * step); } 110 | __CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)(((DevPtr*)this)->data) + y * step); } 111 | 112 | __CV_CUDA_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } 113 | __CV_CUDA_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } 114 | }; 115 | 116 | template struct PtrStepSz : public PtrStep 117 | { 118 | __CV_CUDA_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {} 119 | __CV_CUDA_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_) 120 | : PtrStep(data_, step_), cols(cols_), rows(rows_) {} 121 | 122 | template 123 | explicit PtrStepSz(const PtrStepSz& d) : PtrStep((T*)d.data, d.step), cols(d.cols), rows(d.rows){} 124 | 125 | int cols; 126 | int rows; 127 | }; 128 | 129 | typedef PtrStepSz PtrStepSzb; 130 | typedef PtrStepSz PtrStepSzus; 131 | typedef PtrStepSz PtrStepSzf; 132 | typedef PtrStepSz PtrStepSzi; 133 | 134 | typedef PtrStep PtrStepb; 135 | typedef PtrStep PtrStepus; 136 | typedef PtrStep PtrStepf; 137 | typedef PtrStep PtrStepi; 138 | 139 | } 140 | } 141 | 142 | //! @endcond 143 | 144 | #endif /* OPENCV_CORE_CUDA_TYPES_HPP */ 145 | -------------------------------------------------------------------------------- /opencv/opencv2/core/detail/async_promise.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_ASYNC_PROMISE_HPP 6 | #define OPENCV_CORE_ASYNC_PROMISE_HPP 7 | 8 | #include "../async.hpp" 9 | 10 | #include "exception_ptr.hpp" 11 | 12 | namespace cv { 13 | 14 | /** @addtogroup core_async 15 | @{ 16 | */ 17 | 18 | 19 | /** @brief Provides result of asynchronous operations 20 | 21 | */ 22 | class CV_EXPORTS AsyncPromise 23 | { 24 | public: 25 | ~AsyncPromise() CV_NOEXCEPT; 26 | AsyncPromise() CV_NOEXCEPT; 27 | explicit AsyncPromise(const AsyncPromise& o) CV_NOEXCEPT; 28 | AsyncPromise& operator=(const AsyncPromise& o) CV_NOEXCEPT; 29 | void release() CV_NOEXCEPT; 30 | 31 | /** Returns associated AsyncArray 32 | @note Can be called once 33 | */ 34 | AsyncArray getArrayResult(); 35 | 36 | /** Stores asynchronous result. 37 | @param[in] value result 38 | */ 39 | void setValue(InputArray value); 40 | 41 | // TODO "move" setters 42 | 43 | #if CV__EXCEPTION_PTR 44 | /** Stores exception. 45 | @param[in] exception exception to be raised in AsyncArray 46 | */ 47 | void setException(std::exception_ptr exception); 48 | #endif 49 | 50 | /** Stores exception. 51 | @param[in] exception exception to be raised in AsyncArray 52 | */ 53 | void setException(const cv::Exception& exception); 54 | 55 | explicit AsyncPromise(AsyncPromise&& o) { p = o.p; o.p = NULL; } 56 | AsyncPromise& operator=(AsyncPromise&& o) CV_NOEXCEPT { std::swap(p, o.p); return *this; } 57 | 58 | 59 | // PImpl 60 | typedef struct AsyncArray::Impl Impl; friend struct AsyncArray::Impl; 61 | inline void* _getImpl() const CV_NOEXCEPT { return p; } 62 | protected: 63 | Impl* p; 64 | }; 65 | 66 | 67 | //! @} 68 | } // namespace 69 | #endif // OPENCV_CORE_ASYNC_PROMISE_HPP 70 | -------------------------------------------------------------------------------- /opencv/opencv2/core/detail/dispatch_helper.impl.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_DETAIL_DISPATCH_HELPER_IMPL_HPP 6 | #define OPENCV_CORE_DETAIL_DISPATCH_HELPER_IMPL_HPP 7 | 8 | //! @cond IGNORED 9 | 10 | namespace cv { 11 | namespace detail { 12 | 13 | template class Functor, typename... Args> 14 | static inline void depthDispatch(const int depth, Args&&... args) 15 | { 16 | switch (depth) 17 | { 18 | case CV_8U: 19 | Functor{}(std::forward(args)...); 20 | break; 21 | case CV_8S: 22 | Functor{}(std::forward(args)...); 23 | break; 24 | case CV_16U: 25 | Functor{}(std::forward(args)...); 26 | break; 27 | case CV_16S: 28 | Functor{}(std::forward(args)...); 29 | break; 30 | case CV_32S: 31 | Functor{}(std::forward(args)...); 32 | break; 33 | case CV_32F: 34 | Functor{}(std::forward(args)...); 35 | break; 36 | case CV_64F: 37 | Functor{}(std::forward(args)...); 38 | break; 39 | case CV_16F: 40 | default: 41 | CV_Error(cv::Error::BadDepth, "Unsupported matrix type."); 42 | }; 43 | } 44 | 45 | }} 46 | 47 | //! @endcond 48 | 49 | #endif //OPENCV_CORE_DETAIL_DISPATCH_HELPER_IMPL_HPP 50 | -------------------------------------------------------------------------------- /opencv/opencv2/core/detail/exception_ptr.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_DETAILS_EXCEPTION_PTR_H 6 | #define OPENCV_CORE_DETAILS_EXCEPTION_PTR_H 7 | 8 | #ifndef CV__EXCEPTION_PTR 9 | # if defined(__ANDROID__) && defined(ATOMIC_INT_LOCK_FREE) && ATOMIC_INT_LOCK_FREE < 2 10 | # define CV__EXCEPTION_PTR 0 // Not supported, details: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58938 11 | # else 12 | # define CV__EXCEPTION_PTR 1 13 | # endif 14 | #endif 15 | #ifndef CV__EXCEPTION_PTR 16 | # define CV__EXCEPTION_PTR 0 17 | #elif CV__EXCEPTION_PTR 18 | # include // std::exception_ptr 19 | #endif 20 | 21 | #endif // OPENCV_CORE_DETAILS_EXCEPTION_PTR_H 22 | -------------------------------------------------------------------------------- /opencv/opencv2/core/hal/interface.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENCV_CORE_HAL_INTERFACE_H 2 | #define OPENCV_CORE_HAL_INTERFACE_H 3 | 4 | //! @addtogroup core_hal_interface 5 | //! @{ 6 | 7 | //! @name Return codes 8 | //! @{ 9 | #define CV_HAL_ERROR_OK 0 10 | #define CV_HAL_ERROR_NOT_IMPLEMENTED 1 11 | #define CV_HAL_ERROR_UNKNOWN -1 12 | //! @} 13 | 14 | #ifdef __cplusplus 15 | #include 16 | #else 17 | #include 18 | #include 19 | #endif 20 | 21 | //! @name Data types 22 | //! primitive types 23 | //! - schar - signed 1 byte integer 24 | //! - uchar - unsigned 1 byte integer 25 | //! - short - signed 2 byte integer 26 | //! - ushort - unsigned 2 byte integer 27 | //! - int - signed 4 byte integer 28 | //! - uint - unsigned 4 byte integer 29 | //! - int64 - signed 8 byte integer 30 | //! - uint64 - unsigned 8 byte integer 31 | //! @{ 32 | #if !defined _MSC_VER && !defined __BORLANDC__ 33 | # if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__ 34 | # include 35 | # ifdef __NEWLIB__ 36 | typedef unsigned int uint; 37 | # else 38 | typedef std::uint32_t uint; 39 | # endif 40 | # else 41 | # include 42 | typedef uint32_t uint; 43 | # endif 44 | #else 45 | typedef unsigned uint; 46 | #endif 47 | 48 | typedef signed char schar; 49 | 50 | #ifndef __IPL_H__ 51 | typedef unsigned char uchar; 52 | typedef unsigned short ushort; 53 | #endif 54 | 55 | #if defined _MSC_VER || defined __BORLANDC__ 56 | typedef __int64 int64; 57 | typedef unsigned __int64 uint64; 58 | # define CV_BIG_INT(n) n##I64 59 | # define CV_BIG_UINT(n) n##UI64 60 | #else 61 | typedef int64_t int64; 62 | typedef uint64_t uint64; 63 | # define CV_BIG_INT(n) n##LL 64 | # define CV_BIG_UINT(n) n##ULL 65 | #endif 66 | 67 | #define CV_USRTYPE1 (void)"CV_USRTYPE1 support has been dropped in OpenCV 4.0" 68 | 69 | #define CV_CN_MAX 512 70 | #define CV_CN_SHIFT 3 71 | #define CV_DEPTH_MAX (1 << CV_CN_SHIFT) 72 | 73 | #define CV_8U 0 74 | #define CV_8S 1 75 | #define CV_16U 2 76 | #define CV_16S 3 77 | #define CV_32S 4 78 | #define CV_32F 5 79 | #define CV_64F 6 80 | #define CV_16F 7 81 | 82 | #define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1) 83 | #define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK) 84 | 85 | #define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT)) 86 | #define CV_MAKE_TYPE CV_MAKETYPE 87 | 88 | #define CV_8UC1 CV_MAKETYPE(CV_8U,1) 89 | #define CV_8UC2 CV_MAKETYPE(CV_8U,2) 90 | #define CV_8UC3 CV_MAKETYPE(CV_8U,3) 91 | #define CV_8UC4 CV_MAKETYPE(CV_8U,4) 92 | #define CV_8UC(n) CV_MAKETYPE(CV_8U,(n)) 93 | 94 | #define CV_8SC1 CV_MAKETYPE(CV_8S,1) 95 | #define CV_8SC2 CV_MAKETYPE(CV_8S,2) 96 | #define CV_8SC3 CV_MAKETYPE(CV_8S,3) 97 | #define CV_8SC4 CV_MAKETYPE(CV_8S,4) 98 | #define CV_8SC(n) CV_MAKETYPE(CV_8S,(n)) 99 | 100 | #define CV_16UC1 CV_MAKETYPE(CV_16U,1) 101 | #define CV_16UC2 CV_MAKETYPE(CV_16U,2) 102 | #define CV_16UC3 CV_MAKETYPE(CV_16U,3) 103 | #define CV_16UC4 CV_MAKETYPE(CV_16U,4) 104 | #define CV_16UC(n) CV_MAKETYPE(CV_16U,(n)) 105 | 106 | #define CV_16SC1 CV_MAKETYPE(CV_16S,1) 107 | #define CV_16SC2 CV_MAKETYPE(CV_16S,2) 108 | #define CV_16SC3 CV_MAKETYPE(CV_16S,3) 109 | #define CV_16SC4 CV_MAKETYPE(CV_16S,4) 110 | #define CV_16SC(n) CV_MAKETYPE(CV_16S,(n)) 111 | 112 | #define CV_32SC1 CV_MAKETYPE(CV_32S,1) 113 | #define CV_32SC2 CV_MAKETYPE(CV_32S,2) 114 | #define CV_32SC3 CV_MAKETYPE(CV_32S,3) 115 | #define CV_32SC4 CV_MAKETYPE(CV_32S,4) 116 | #define CV_32SC(n) CV_MAKETYPE(CV_32S,(n)) 117 | 118 | #define CV_32FC1 CV_MAKETYPE(CV_32F,1) 119 | #define CV_32FC2 CV_MAKETYPE(CV_32F,2) 120 | #define CV_32FC3 CV_MAKETYPE(CV_32F,3) 121 | #define CV_32FC4 CV_MAKETYPE(CV_32F,4) 122 | #define CV_32FC(n) CV_MAKETYPE(CV_32F,(n)) 123 | 124 | #define CV_64FC1 CV_MAKETYPE(CV_64F,1) 125 | #define CV_64FC2 CV_MAKETYPE(CV_64F,2) 126 | #define CV_64FC3 CV_MAKETYPE(CV_64F,3) 127 | #define CV_64FC4 CV_MAKETYPE(CV_64F,4) 128 | #define CV_64FC(n) CV_MAKETYPE(CV_64F,(n)) 129 | 130 | #define CV_16FC1 CV_MAKETYPE(CV_16F,1) 131 | #define CV_16FC2 CV_MAKETYPE(CV_16F,2) 132 | #define CV_16FC3 CV_MAKETYPE(CV_16F,3) 133 | #define CV_16FC4 CV_MAKETYPE(CV_16F,4) 134 | #define CV_16FC(n) CV_MAKETYPE(CV_16F,(n)) 135 | //! @} 136 | 137 | //! @name Comparison operation 138 | //! @sa cv::CmpTypes 139 | //! @{ 140 | #define CV_HAL_CMP_EQ 0 141 | #define CV_HAL_CMP_GT 1 142 | #define CV_HAL_CMP_GE 2 143 | #define CV_HAL_CMP_LT 3 144 | #define CV_HAL_CMP_LE 4 145 | #define CV_HAL_CMP_NE 5 146 | //! @} 147 | 148 | //! @name Border processing modes 149 | //! @sa cv::BorderTypes 150 | //! @{ 151 | #define CV_HAL_BORDER_CONSTANT 0 152 | #define CV_HAL_BORDER_REPLICATE 1 153 | #define CV_HAL_BORDER_REFLECT 2 154 | #define CV_HAL_BORDER_WRAP 3 155 | #define CV_HAL_BORDER_REFLECT_101 4 156 | #define CV_HAL_BORDER_TRANSPARENT 5 157 | #define CV_HAL_BORDER_ISOLATED 16 158 | //! @} 159 | 160 | //! @name DFT flags 161 | //! @{ 162 | #define CV_HAL_DFT_INVERSE 1 163 | #define CV_HAL_DFT_SCALE 2 164 | #define CV_HAL_DFT_ROWS 4 165 | #define CV_HAL_DFT_COMPLEX_OUTPUT 16 166 | #define CV_HAL_DFT_REAL_OUTPUT 32 167 | #define CV_HAL_DFT_TWO_STAGE 64 168 | #define CV_HAL_DFT_STAGE_COLS 128 169 | #define CV_HAL_DFT_IS_CONTINUOUS 512 170 | #define CV_HAL_DFT_IS_INPLACE 1024 171 | //! @} 172 | 173 | //! @name SVD flags 174 | //! @{ 175 | #define CV_HAL_SVD_NO_UV 1 176 | #define CV_HAL_SVD_SHORT_UV 2 177 | #define CV_HAL_SVD_MODIFY_A 4 178 | #define CV_HAL_SVD_FULL_UV 8 179 | //! @} 180 | 181 | //! @name Gemm flags 182 | //! @{ 183 | #define CV_HAL_GEMM_1_T 1 184 | #define CV_HAL_GEMM_2_T 2 185 | #define CV_HAL_GEMM_3_T 4 186 | //! @} 187 | 188 | //! @} 189 | 190 | #endif 191 | -------------------------------------------------------------------------------- /opencv/opencv2/core/hal/intrin_rvv_011_compat.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | // 0.11 -> 0.12 compatibility 6 | 7 | #ifndef _RVV_IMPLICIT_VXRM 8 | #define _RVV_IMPLICIT_VXRM __RISCV_VXRM_RNU 9 | #endif 10 | 11 | // NOTE: masked should go first to avoid extra substitution (3 arg -> 4 arg -> 5 arg) 12 | 13 | // masked 14 | #define __riscv_vaadd(_1, _2, _3, _4) __riscv_vaadd(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 15 | #define __riscv_vasub(_1, _2, _3, _4) __riscv_vasub(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 16 | #define __riscv_vaaddu(_1, _2, _3, _4) __riscv_vaaddu(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 17 | #define __riscv_vasubu(_1, _2, _3, _4) __riscv_vasubu(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 18 | #define __riscv_vsmul(_1, _2, _3, _4) __riscv_vsmul(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 19 | #define __riscv_vssra(_1, _2, _3, _4) __riscv_vssra(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 20 | #define __riscv_vssrl(_1, _2, _3, _4) __riscv_vssrl(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 21 | #define __riscv_vnclip(_1, _2, _3, _4) __riscv_vnclip(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 22 | #define __riscv_vnclipu(_1, _2, _3, _4) __riscv_vnclipu(_1, _2, _3, _RVV_IMPLICIT_VXRM, _4) 23 | 24 | // unmasked 25 | #define __riscv_vaadd(_1, _2, _3) __riscv_vaadd(_1, _2, _RVV_IMPLICIT_VXRM, _3) 26 | #define __riscv_vasub(_1, _2, _3) __riscv_vasub(_1, _2, _RVV_IMPLICIT_VXRM, _3) 27 | #define __riscv_vaaddu(_1, _2, _3) __riscv_vaaddu(_1, _2, _RVV_IMPLICIT_VXRM, _3) 28 | #define __riscv_vasubu(_1, _2, _3) __riscv_vasubu(_1, _2, _RVV_IMPLICIT_VXRM, _3) 29 | #define __riscv_vsmul(_1, _2, _3) __riscv_vsmul(_1, _2, _RVV_IMPLICIT_VXRM, _3) 30 | #define __riscv_vssra(_1, _2, _3) __riscv_vssra(_1, _2, _RVV_IMPLICIT_VXRM, _3) 31 | #define __riscv_vssrl(_1, _2, _3) __riscv_vssrl(_1, _2, _RVV_IMPLICIT_VXRM, _3) 32 | #define __riscv_vnclip(_1, _2, _3) __riscv_vnclip(_1, _2, _RVV_IMPLICIT_VXRM, _3) 33 | #define __riscv_vnclipu(_1, _2, _3) __riscv_vnclipu(_1, _2, _RVV_IMPLICIT_VXRM, _3) 34 | -------------------------------------------------------------------------------- /opencv/opencv2/core/neon_utils.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2015, Itseez Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the Intel Corporation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_HAL_NEON_UTILS_HPP 43 | #define OPENCV_HAL_NEON_UTILS_HPP 44 | 45 | #include "opencv2/core/cvdef.h" 46 | 47 | //! @addtogroup core_utils_neon 48 | //! @{ 49 | 50 | #if CV_NEON 51 | 52 | inline int32x2_t cv_vrnd_s32_f32(float32x2_t v) 53 | { 54 | static int32x2_t v_sign = vdup_n_s32(1 << 31), 55 | v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f)); 56 | 57 | int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v))); 58 | return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition))); 59 | } 60 | 61 | inline int32x4_t cv_vrndq_s32_f32(float32x4_t v) 62 | { 63 | static int32x4_t v_sign = vdupq_n_s32(1 << 31), 64 | v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); 65 | 66 | int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v))); 67 | return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition))); 68 | } 69 | 70 | inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v) 71 | { 72 | static float32x2_t v_05 = vdup_n_f32(0.5f); 73 | return vcvt_u32_f32(vadd_f32(v, v_05)); 74 | } 75 | 76 | inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v) 77 | { 78 | static float32x4_t v_05 = vdupq_n_f32(0.5f); 79 | return vcvtq_u32_f32(vaddq_f32(v, v_05)); 80 | } 81 | 82 | inline float32x4_t cv_vrecpq_f32(float32x4_t val) 83 | { 84 | float32x4_t reciprocal = vrecpeq_f32(val); 85 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); 86 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); 87 | return reciprocal; 88 | } 89 | 90 | inline float32x2_t cv_vrecp_f32(float32x2_t val) 91 | { 92 | float32x2_t reciprocal = vrecpe_f32(val); 93 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); 94 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); 95 | return reciprocal; 96 | } 97 | 98 | inline float32x4_t cv_vrsqrtq_f32(float32x4_t val) 99 | { 100 | float32x4_t e = vrsqrteq_f32(val); 101 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); 102 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); 103 | return e; 104 | } 105 | 106 | inline float32x2_t cv_vrsqrt_f32(float32x2_t val) 107 | { 108 | float32x2_t e = vrsqrte_f32(val); 109 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); 110 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); 111 | return e; 112 | } 113 | 114 | inline float32x4_t cv_vsqrtq_f32(float32x4_t val) 115 | { 116 | return cv_vrecpq_f32(cv_vrsqrtq_f32(val)); 117 | } 118 | 119 | inline float32x2_t cv_vsqrt_f32(float32x2_t val) 120 | { 121 | return cv_vrecp_f32(cv_vrsqrt_f32(val)); 122 | } 123 | 124 | #endif 125 | 126 | //! @} 127 | 128 | #endif // OPENCV_HAL_NEON_UTILS_HPP 129 | -------------------------------------------------------------------------------- /opencv/opencv2/core/ocl_genbase.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_OPENCL_GENBASE_HPP 43 | #define OPENCV_OPENCL_GENBASE_HPP 44 | 45 | //! @cond IGNORED 46 | 47 | namespace cv { 48 | namespace ocl { 49 | 50 | class ProgramSource; 51 | 52 | namespace internal { 53 | 54 | struct CV_EXPORTS ProgramEntry 55 | { 56 | const char* module; 57 | const char* name; 58 | const char* programCode; 59 | const char* programHash; 60 | ProgramSource* pProgramSource; 61 | 62 | operator ProgramSource& () const; 63 | }; 64 | 65 | } } } // namespace 66 | 67 | //! @endcond 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/ocl_defs.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. 6 | // Third party copyrights are property of their respective owners. 7 | 8 | #ifndef OPENCV_CORE_OPENCL_DEFS_HPP 9 | #define OPENCV_CORE_OPENCL_DEFS_HPP 10 | 11 | #include "opencv2/core/utility.hpp" 12 | #include "cvconfig.h" 13 | 14 | namespace cv { namespace ocl { 15 | #ifdef HAVE_OPENCL 16 | /// Call is similar to useOpenCL() but doesn't try to load OpenCL runtime or create OpenCL context 17 | CV_EXPORTS bool isOpenCLActivated(); 18 | #else 19 | static inline bool isOpenCLActivated() { return false; } 20 | #endif 21 | }} // namespace 22 | 23 | 24 | //#define CV_OPENCL_RUN_ASSERT 25 | 26 | #ifdef HAVE_OPENCL 27 | 28 | #ifdef CV_OPENCL_RUN_VERBOSE 29 | #define CV_OCL_RUN_(condition, func, ...) \ 30 | { \ 31 | if (cv::ocl::isOpenCLActivated() && (condition) && func) \ 32 | { \ 33 | printf("%s: OpenCL implementation is running\n", CV_Func); \ 34 | fflush(stdout); \ 35 | CV_IMPL_ADD(CV_IMPL_OCL); \ 36 | return __VA_ARGS__; \ 37 | } \ 38 | else \ 39 | { \ 40 | printf("%s: Plain implementation is running\n", CV_Func); \ 41 | fflush(stdout); \ 42 | } \ 43 | } 44 | #elif defined CV_OPENCL_RUN_ASSERT 45 | #define CV_OCL_RUN_(condition, func, ...) \ 46 | { \ 47 | if (cv::ocl::isOpenCLActivated() && (condition)) \ 48 | { \ 49 | if(func) \ 50 | { \ 51 | CV_IMPL_ADD(CV_IMPL_OCL); \ 52 | } \ 53 | else \ 54 | { \ 55 | CV_Error(cv::Error::StsAssert, #func); \ 56 | } \ 57 | return __VA_ARGS__; \ 58 | } \ 59 | } 60 | #else 61 | #define CV_OCL_RUN_(condition, func, ...) \ 62 | try \ 63 | { \ 64 | if (cv::ocl::isOpenCLActivated() && (condition) && func) \ 65 | { \ 66 | CV_IMPL_ADD(CV_IMPL_OCL); \ 67 | return __VA_ARGS__; \ 68 | } \ 69 | } \ 70 | catch (const cv::Exception& e) \ 71 | { \ 72 | CV_UNUSED(e); /* TODO: Add some logging here */ \ 73 | } 74 | #endif 75 | 76 | #else 77 | #define CV_OCL_RUN_(condition, func, ...) 78 | #endif 79 | 80 | #define CV_OCL_RUN(condition, func) CV_OCL_RUN_(condition, func) 81 | 82 | #endif // OPENCV_CORE_OPENCL_DEFS_HPP 83 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/opencl_svm.hpp: -------------------------------------------------------------------------------- 1 | /* See LICENSE file in the root OpenCV directory */ 2 | 3 | #ifndef OPENCV_CORE_OPENCL_SVM_HPP 4 | #define OPENCV_CORE_OPENCL_SVM_HPP 5 | 6 | // 7 | // Internal usage only (binary compatibility is not guaranteed) 8 | // 9 | #ifndef __OPENCV_BUILD 10 | #error Internal header file 11 | #endif 12 | 13 | #if defined(HAVE_OPENCL) && defined(HAVE_OPENCL_SVM) 14 | #include "runtime/opencl_core.hpp" 15 | #include "runtime/opencl_svm_20.hpp" 16 | #include "runtime/opencl_svm_hsa_extension.hpp" 17 | 18 | namespace cv { namespace ocl { namespace svm { 19 | 20 | struct SVMCapabilities 21 | { 22 | enum Value 23 | { 24 | SVM_COARSE_GRAIN_BUFFER = (1 << 0), 25 | SVM_FINE_GRAIN_BUFFER = (1 << 1), 26 | SVM_FINE_GRAIN_SYSTEM = (1 << 2), 27 | SVM_ATOMICS = (1 << 3), 28 | }; 29 | int value_; 30 | 31 | SVMCapabilities(int capabilities = 0) : value_(capabilities) { } 32 | operator int() const { return value_; } 33 | 34 | inline bool isNoSVMSupport() const { return value_ == 0; } 35 | inline bool isSupportCoarseGrainBuffer() const { return (value_ & SVM_COARSE_GRAIN_BUFFER) != 0; } 36 | inline bool isSupportFineGrainBuffer() const { return (value_ & SVM_FINE_GRAIN_BUFFER) != 0; } 37 | inline bool isSupportFineGrainSystem() const { return (value_ & SVM_FINE_GRAIN_SYSTEM) != 0; } 38 | inline bool isSupportAtomics() const { return (value_ & SVM_ATOMICS) != 0; } 39 | }; 40 | 41 | CV_EXPORTS const SVMCapabilities getSVMCapabilitites(const ocl::Context& context); 42 | 43 | struct SVMFunctions 44 | { 45 | clSVMAllocAMD_fn fn_clSVMAlloc; 46 | clSVMFreeAMD_fn fn_clSVMFree; 47 | clSetKernelArgSVMPointerAMD_fn fn_clSetKernelArgSVMPointer; 48 | //clSetKernelExecInfoAMD_fn fn_clSetKernelExecInfo; 49 | //clEnqueueSVMFreeAMD_fn fn_clEnqueueSVMFree; 50 | clEnqueueSVMMemcpyAMD_fn fn_clEnqueueSVMMemcpy; 51 | clEnqueueSVMMemFillAMD_fn fn_clEnqueueSVMMemFill; 52 | clEnqueueSVMMapAMD_fn fn_clEnqueueSVMMap; 53 | clEnqueueSVMUnmapAMD_fn fn_clEnqueueSVMUnmap; 54 | 55 | inline SVMFunctions() 56 | : fn_clSVMAlloc(NULL), fn_clSVMFree(NULL), 57 | fn_clSetKernelArgSVMPointer(NULL), /*fn_clSetKernelExecInfo(NULL),*/ 58 | /*fn_clEnqueueSVMFree(NULL),*/ fn_clEnqueueSVMMemcpy(NULL), fn_clEnqueueSVMMemFill(NULL), 59 | fn_clEnqueueSVMMap(NULL), fn_clEnqueueSVMUnmap(NULL) 60 | { 61 | // nothing 62 | } 63 | 64 | inline bool isValid() const 65 | { 66 | return fn_clSVMAlloc != NULL && fn_clSVMFree && fn_clSetKernelArgSVMPointer && 67 | /*fn_clSetKernelExecInfo && fn_clEnqueueSVMFree &&*/ fn_clEnqueueSVMMemcpy && 68 | fn_clEnqueueSVMMemFill && fn_clEnqueueSVMMap && fn_clEnqueueSVMUnmap; 69 | } 70 | }; 71 | 72 | // We should guarantee that SVMFunctions lifetime is not less than context's lifetime 73 | CV_EXPORTS const SVMFunctions* getSVMFunctions(const ocl::Context& context); 74 | 75 | CV_EXPORTS bool useSVM(UMatUsageFlags usageFlags); 76 | 77 | }}} //namespace cv::ocl::svm 78 | #endif 79 | 80 | #endif // OPENCV_CORE_OPENCL_SVM_HPP 81 | /* End of file. */ 82 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // AUTOGENERATED, DO NOT EDIT 3 | // 4 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP 5 | #error "Invalid usage" 6 | #endif 7 | 8 | // generated by parser_cl.py 9 | #define clCreateFromGLBuffer clCreateFromGLBuffer_ 10 | #define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_ 11 | #define clCreateFromGLTexture clCreateFromGLTexture_ 12 | #define clCreateFromGLTexture2D clCreateFromGLTexture2D_ 13 | #define clCreateFromGLTexture3D clCreateFromGLTexture3D_ 14 | #define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_ 15 | #define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_ 16 | #define clGetGLContextInfoKHR clGetGLContextInfoKHR_ 17 | #define clGetGLObjectInfo clGetGLObjectInfo_ 18 | #define clGetGLTextureInfo clGetGLTextureInfo_ 19 | 20 | #if defined __APPLE__ 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | // generated by parser_cl.py 27 | #undef clCreateFromGLBuffer 28 | #define clCreateFromGLBuffer clCreateFromGLBuffer_pfn 29 | #undef clCreateFromGLRenderbuffer 30 | #define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_pfn 31 | #undef clCreateFromGLTexture 32 | #define clCreateFromGLTexture clCreateFromGLTexture_pfn 33 | #undef clCreateFromGLTexture2D 34 | #define clCreateFromGLTexture2D clCreateFromGLTexture2D_pfn 35 | #undef clCreateFromGLTexture3D 36 | #define clCreateFromGLTexture3D clCreateFromGLTexture3D_pfn 37 | #undef clEnqueueAcquireGLObjects 38 | #define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_pfn 39 | #undef clEnqueueReleaseGLObjects 40 | #define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_pfn 41 | #undef clGetGLContextInfoKHR 42 | #define clGetGLContextInfoKHR clGetGLContextInfoKHR_pfn 43 | #undef clGetGLObjectInfo 44 | #define clGetGLObjectInfo clGetGLObjectInfo_pfn 45 | #undef clGetGLTextureInfo 46 | #define clGetGLTextureInfo clGetGLTextureInfo_pfn 47 | 48 | #ifdef cl_khr_gl_sharing 49 | 50 | // generated by parser_cl.py 51 | extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLBuffer)(cl_context, cl_mem_flags, cl_GLuint, int*); 52 | extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLRenderbuffer)(cl_context, cl_mem_flags, cl_GLuint, cl_int*); 53 | extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); 54 | extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture2D)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); 55 | extern CL_RUNTIME_EXPORT cl_mem (CL_API_CALL*clCreateFromGLTexture3D)(cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int*); 56 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueAcquireGLObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_uint, const cl_event*, cl_event*); 57 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clEnqueueReleaseGLObjects)(cl_command_queue, cl_uint, const cl_mem*, cl_uint, const cl_event*, cl_event*); 58 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLContextInfoKHR)(const cl_context_properties*, cl_gl_context_info, size_t, void*, size_t*); 59 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLObjectInfo)(cl_mem, cl_gl_object_type*, cl_GLuint*); 60 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL*clGetGLTextureInfo)(cl_mem, cl_gl_texture_info, size_t, void*, size_t*); 61 | 62 | #endif // cl_khr_gl_sharing 63 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // AUTOGENERATED, DO NOT EDIT 3 | // 4 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP 5 | #error "Invalid usage" 6 | #endif 7 | 8 | #ifdef cl_khr_gl_sharing 9 | 10 | // generated by parser_cl.py 11 | #undef clCreateFromGLBuffer 12 | #define clCreateFromGLBuffer clCreateFromGLBuffer_fn 13 | inline cl_mem clCreateFromGLBuffer(cl_context p0, cl_mem_flags p1, cl_GLuint p2, int* p3) { return clCreateFromGLBuffer_pfn(p0, p1, p2, p3); } 14 | #undef clCreateFromGLRenderbuffer 15 | #define clCreateFromGLRenderbuffer clCreateFromGLRenderbuffer_fn 16 | inline cl_mem clCreateFromGLRenderbuffer(cl_context p0, cl_mem_flags p1, cl_GLuint p2, cl_int* p3) { return clCreateFromGLRenderbuffer_pfn(p0, p1, p2, p3); } 17 | #undef clCreateFromGLTexture 18 | #define clCreateFromGLTexture clCreateFromGLTexture_fn 19 | inline cl_mem clCreateFromGLTexture(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture_pfn(p0, p1, p2, p3, p4, p5); } 20 | #undef clCreateFromGLTexture2D 21 | #define clCreateFromGLTexture2D clCreateFromGLTexture2D_fn 22 | inline cl_mem clCreateFromGLTexture2D(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture2D_pfn(p0, p1, p2, p3, p4, p5); } 23 | #undef clCreateFromGLTexture3D 24 | #define clCreateFromGLTexture3D clCreateFromGLTexture3D_fn 25 | inline cl_mem clCreateFromGLTexture3D(cl_context p0, cl_mem_flags p1, cl_GLenum p2, cl_GLint p3, cl_GLuint p4, cl_int* p5) { return clCreateFromGLTexture3D_pfn(p0, p1, p2, p3, p4, p5); } 26 | #undef clEnqueueAcquireGLObjects 27 | #define clEnqueueAcquireGLObjects clEnqueueAcquireGLObjects_fn 28 | inline cl_int clEnqueueAcquireGLObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueAcquireGLObjects_pfn(p0, p1, p2, p3, p4, p5); } 29 | #undef clEnqueueReleaseGLObjects 30 | #define clEnqueueReleaseGLObjects clEnqueueReleaseGLObjects_fn 31 | inline cl_int clEnqueueReleaseGLObjects(cl_command_queue p0, cl_uint p1, const cl_mem* p2, cl_uint p3, const cl_event* p4, cl_event* p5) { return clEnqueueReleaseGLObjects_pfn(p0, p1, p2, p3, p4, p5); } 32 | #undef clGetGLContextInfoKHR 33 | #define clGetGLContextInfoKHR clGetGLContextInfoKHR_fn 34 | inline cl_int clGetGLContextInfoKHR(const cl_context_properties* p0, cl_gl_context_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLContextInfoKHR_pfn(p0, p1, p2, p3, p4); } 35 | #undef clGetGLObjectInfo 36 | #define clGetGLObjectInfo clGetGLObjectInfo_fn 37 | inline cl_int clGetGLObjectInfo(cl_mem p0, cl_gl_object_type* p1, cl_GLuint* p2) { return clGetGLObjectInfo_pfn(p0, p1, p2); } 38 | #undef clGetGLTextureInfo 39 | #define clGetGLTextureInfo clGetGLTextureInfo_fn 40 | inline cl_int clGetGLTextureInfo(cl_mem p0, cl_gl_texture_info p1, size_t p2, void* p3, size_t* p4) { return clGetGLTextureInfo_pfn(p0, p1, p2, p3, p4); } 41 | 42 | #endif // cl_khr_gl_sharing 43 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_clblas.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP 43 | #define OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP 44 | 45 | #ifdef HAVE_CLAMDBLAS 46 | 47 | #include "opencl_core.hpp" 48 | 49 | #include "autogenerated/opencl_clblas.hpp" 50 | 51 | #endif // HAVE_CLAMDBLAS 52 | 53 | #endif // OPENCV_CORE_OCL_RUNTIME_CLAMDBLAS_HPP 54 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_clfft.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP 43 | #define OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP 44 | 45 | #ifdef HAVE_CLAMDFFT 46 | 47 | #include "opencl_core.hpp" 48 | 49 | #include "autogenerated/opencl_clfft.hpp" 50 | 51 | #endif // HAVE_CLAMDFFT 52 | 53 | #endif // OPENCV_CORE_OCL_RUNTIME_CLAMDFFT_HPP 54 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_core.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP 43 | #define OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP 44 | 45 | #ifdef HAVE_OPENCL 46 | 47 | #ifndef CL_RUNTIME_EXPORT 48 | #if (defined(BUILD_SHARED_LIBS) || defined(OPENCV_CORE_SHARED)) && (defined _WIN32 || defined WINCE) && \ 49 | !(defined(__OPENCV_BUILD) && defined(OPENCV_MODULE_IS_PART_OF_WORLD)) 50 | #define CL_RUNTIME_EXPORT __declspec(dllimport) 51 | #else 52 | #define CL_RUNTIME_EXPORT 53 | #endif 54 | #endif 55 | 56 | #ifdef HAVE_OPENCL_SVM 57 | #define clSVMAlloc clSVMAlloc_ 58 | #define clSVMFree clSVMFree_ 59 | #define clSetKernelArgSVMPointer clSetKernelArgSVMPointer_ 60 | #define clSetKernelExecInfo clSetKernelExecInfo_ 61 | #define clEnqueueSVMFree clEnqueueSVMFree_ 62 | #define clEnqueueSVMMemcpy clEnqueueSVMMemcpy_ 63 | #define clEnqueueSVMMemFill clEnqueueSVMMemFill_ 64 | #define clEnqueueSVMMap clEnqueueSVMMap_ 65 | #define clEnqueueSVMUnmap clEnqueueSVMUnmap_ 66 | #endif 67 | 68 | #include "autogenerated/opencl_core.hpp" 69 | 70 | #ifndef CL_DEVICE_DOUBLE_FP_CONFIG 71 | #define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 72 | #endif 73 | 74 | #ifndef CL_DEVICE_HALF_FP_CONFIG 75 | #define CL_DEVICE_HALF_FP_CONFIG 0x1033 76 | #endif 77 | 78 | #ifndef CL_VERSION_1_2 79 | #define CV_REQUIRE_OPENCL_1_2_ERROR CV_Error(cv::Error::OpenCLApiCallError, "OpenCV compiled without OpenCL v1.2 support, so we can't use functionality from OpenCL v1.2") 80 | #endif 81 | 82 | #endif // HAVE_OPENCL 83 | 84 | #endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_CORE_HPP 85 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP 43 | #define OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP 44 | 45 | #include "autogenerated/opencl_core_wrappers.hpp" 46 | 47 | #endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_WRAPPERS_HPP 48 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_gl.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP 43 | #define OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP 44 | 45 | #if defined HAVE_OPENCL && defined HAVE_OPENGL 46 | 47 | #include "opencl_core.hpp" 48 | 49 | #include "autogenerated/opencl_gl.hpp" 50 | 51 | #endif // defined HAVE_OPENCL && defined HAVE_OPENGL 52 | 53 | #endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_HPP 54 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. 14 | // Third party copyrights are property of their respective owners. 15 | // 16 | // Redistribution and use in source and binary forms, with or without modification, 17 | // are permitted provided that the following conditions are met: 18 | // 19 | // * Redistribution's of source code must retain the above copyright notice, 20 | // this list of conditions and the following disclaimer. 21 | // 22 | // * Redistribution's in binary form must reproduce the above copyright notice, 23 | // this list of conditions and the following disclaimer in the documentation 24 | // and/or other materials provided with the distribution. 25 | // 26 | // * The name of the copyright holders may not be used to endorse or promote products 27 | // derived from this software without specific prior written permission. 28 | // 29 | // This software is provided by the copyright holders and contributors "as is" and 30 | // any express or implied warranties, including, but not limited to, the implied 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 32 | // In no event shall the OpenCV Foundation or contributors be liable for any direct, 33 | // indirect, incidental, special, exemplary, or consequential damages 34 | // (including, but not limited to, procurement of substitute goods or services; 35 | // loss of use, data, or profits; or business interruption) however caused 36 | // and on any theory of liability, whether in contract, strict liability, 37 | // or tort (including negligence or otherwise) arising in any way out of 38 | // the use of this software, even if advised of the possibility of such damage. 39 | // 40 | //M*/ 41 | 42 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP 43 | #define OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP 44 | 45 | #include "autogenerated/opencl_gl_wrappers.hpp" 46 | 47 | #endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_GL_WRAPPERS_HPP 48 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_svm_20.hpp: -------------------------------------------------------------------------------- 1 | /* See LICENSE file in the root OpenCV directory */ 2 | 3 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP 4 | #define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP 5 | 6 | #if defined(HAVE_OPENCL_SVM) 7 | #include "opencl_core.hpp" 8 | 9 | #include "opencl_svm_definitions.hpp" 10 | 11 | #undef clSVMAlloc 12 | #define clSVMAlloc clSVMAlloc_pfn 13 | #undef clSVMFree 14 | #define clSVMFree clSVMFree_pfn 15 | #undef clSetKernelArgSVMPointer 16 | #define clSetKernelArgSVMPointer clSetKernelArgSVMPointer_pfn 17 | #undef clSetKernelExecInfo 18 | //#define clSetKernelExecInfo clSetKernelExecInfo_pfn 19 | #undef clEnqueueSVMFree 20 | //#define clEnqueueSVMFree clEnqueueSVMFree_pfn 21 | #undef clEnqueueSVMMemcpy 22 | #define clEnqueueSVMMemcpy clEnqueueSVMMemcpy_pfn 23 | #undef clEnqueueSVMMemFill 24 | #define clEnqueueSVMMemFill clEnqueueSVMMemFill_pfn 25 | #undef clEnqueueSVMMap 26 | #define clEnqueueSVMMap clEnqueueSVMMap_pfn 27 | #undef clEnqueueSVMUnmap 28 | #define clEnqueueSVMUnmap clEnqueueSVMUnmap_pfn 29 | 30 | extern CL_RUNTIME_EXPORT void* (CL_API_CALL *clSVMAlloc)(cl_context context, cl_svm_mem_flags flags, size_t size, unsigned int alignment); 31 | extern CL_RUNTIME_EXPORT void (CL_API_CALL *clSVMFree)(cl_context context, void* svm_pointer); 32 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clSetKernelArgSVMPointer)(cl_kernel kernel, cl_uint arg_index, const void* arg_value); 33 | //extern CL_RUNTIME_EXPORT void* (CL_API_CALL *clSetKernelExecInfo)(cl_kernel kernel, cl_kernel_exec_info param_name, size_t param_value_size, const void* param_value); 34 | //extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMFree)(cl_command_queue command_queue, cl_uint num_svm_pointers, void* svm_pointers[], 35 | // void (CL_CALLBACK *pfn_free_func)(cl_command_queue queue, cl_uint num_svm_pointers, void* svm_pointers[], void* user_data), void* user_data, 36 | // cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); 37 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMemcpy)(cl_command_queue command_queue, cl_bool blocking_copy, void* dst_ptr, const void* src_ptr, size_t size, 38 | cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); 39 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMemFill)(cl_command_queue command_queue, void* svm_ptr, const void* pattern, size_t pattern_size, size_t size, 40 | cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); 41 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMMap)(cl_command_queue command_queue, cl_bool blocking_map, cl_map_flags map_flags, void* svm_ptr, size_t size, 42 | cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); 43 | extern CL_RUNTIME_EXPORT cl_int (CL_API_CALL *clEnqueueSVMUnmap)(cl_command_queue command_queue, void* svm_ptr, 44 | cl_uint num_events_in_wait_list, const cl_event* event_wait_list, cl_event* event); 45 | 46 | #endif // HAVE_OPENCL_SVM 47 | 48 | #endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_2_0_HPP 49 | -------------------------------------------------------------------------------- /opencv/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp: -------------------------------------------------------------------------------- 1 | /* See LICENSE file in the root OpenCV directory */ 2 | 3 | #ifndef OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP 4 | #define OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP 5 | 6 | #if defined(HAVE_OPENCL_SVM) 7 | #if defined(CL_VERSION_2_0) 8 | 9 | // OpenCL 2.0 contains SVM definitions 10 | 11 | #else 12 | 13 | typedef cl_bitfield cl_device_svm_capabilities; 14 | typedef cl_bitfield cl_svm_mem_flags; 15 | typedef cl_uint cl_kernel_exec_info; 16 | 17 | // 18 | // TODO Add real values after OpenCL 2.0 release 19 | // 20 | 21 | #ifndef CL_DEVICE_SVM_CAPABILITIES 22 | #define CL_DEVICE_SVM_CAPABILITIES 0x1053 23 | 24 | #define CL_DEVICE_SVM_COARSE_GRAIN_BUFFER (1 << 0) 25 | #define CL_DEVICE_SVM_FINE_GRAIN_BUFFER (1 << 1) 26 | #define CL_DEVICE_SVM_FINE_GRAIN_SYSTEM (1 << 2) 27 | #define CL_DEVICE_SVM_ATOMICS (1 << 3) 28 | #endif 29 | 30 | #ifndef CL_MEM_SVM_FINE_GRAIN_BUFFER 31 | #define CL_MEM_SVM_FINE_GRAIN_BUFFER (1 << 10) 32 | #endif 33 | 34 | #ifndef CL_MEM_SVM_ATOMICS 35 | #define CL_MEM_SVM_ATOMICS (1 << 11) 36 | #endif 37 | 38 | 39 | #endif // CL_VERSION_2_0 40 | #endif // HAVE_OPENCL_SVM 41 | 42 | #endif // OPENCV_CORE_OCL_RUNTIME_OPENCL_SVM_DEFINITIONS_HPP 43 | -------------------------------------------------------------------------------- /opencv/opencv2/core/ovx.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | // Copyright (C) 2016, Intel Corporation, all rights reserved. 6 | // Third party copyrights are property of their respective owners. 7 | 8 | // OpenVX related definitions and declarations 9 | 10 | #pragma once 11 | #ifndef OPENCV_OVX_HPP 12 | #define OPENCV_OVX_HPP 13 | 14 | #include "cvdef.h" 15 | 16 | namespace cv 17 | { 18 | /// Check if use of OpenVX is possible 19 | CV_EXPORTS_W bool haveOpenVX(); 20 | 21 | /// Check if use of OpenVX is enabled 22 | CV_EXPORTS_W bool useOpenVX(); 23 | 24 | /// Enable/disable use of OpenVX 25 | CV_EXPORTS_W void setUseOpenVX(bool flag); 26 | } // namespace cv 27 | 28 | #endif // OPENCV_OVX_HPP 29 | -------------------------------------------------------------------------------- /opencv/opencv2/core/parallel/backend/parallel_for.openmp.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP 6 | #define OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP 7 | 8 | #include "opencv2/core/parallel/parallel_backend.hpp" 9 | 10 | #if !defined(_OPENMP) && !defined(OPENCV_SKIP_OPENMP_PRESENSE_CHECK) 11 | #error "This file must be compiled with enabled OpenMP" 12 | #endif 13 | 14 | #include 15 | 16 | namespace cv { namespace parallel { namespace openmp { 17 | 18 | /** OpenMP parallel_for API implementation 19 | * 20 | * @sa setParallelForBackend 21 | * @ingroup core_parallel_backend 22 | */ 23 | class ParallelForBackend : public ParallelForAPI 24 | { 25 | protected: 26 | int numThreads; 27 | int numThreadsMax; 28 | public: 29 | ParallelForBackend() 30 | { 31 | numThreads = 0; 32 | numThreadsMax = omp_get_max_threads(); 33 | } 34 | 35 | virtual ~ParallelForBackend() {} 36 | 37 | virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void* callback_data) CV_OVERRIDE 38 | { 39 | #pragma omp parallel for schedule(dynamic) num_threads(numThreads > 0 ? numThreads : numThreadsMax) 40 | for (int i = 0; i < tasks; ++i) 41 | body_callback(i, i + 1, callback_data); 42 | } 43 | 44 | virtual int getThreadNum() const CV_OVERRIDE 45 | { 46 | return omp_get_thread_num(); 47 | } 48 | 49 | virtual int getNumThreads() const CV_OVERRIDE 50 | { 51 | return numThreads > 0 52 | ? numThreads 53 | : numThreadsMax; 54 | } 55 | 56 | virtual int setNumThreads(int nThreads) CV_OVERRIDE 57 | { 58 | int oldNumThreads = numThreads; 59 | numThreads = nThreads; 60 | // nothing needed as numThreads is used in #pragma omp parallel for directly 61 | return oldNumThreads; 62 | } 63 | 64 | const char* getName() const CV_OVERRIDE 65 | { 66 | return "openmp"; 67 | } 68 | }; 69 | 70 | }}} // namespace 71 | 72 | #endif // OPENCV_CORE_PARALLEL_FOR_OPENMP_HPP 73 | -------------------------------------------------------------------------------- /opencv/opencv2/core/parallel/backend/parallel_for.tbb.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_PARALLEL_FOR_TBB_HPP 6 | #define OPENCV_CORE_PARALLEL_FOR_TBB_HPP 7 | 8 | #include "opencv2/core/parallel/parallel_backend.hpp" 9 | #include 10 | 11 | #ifndef TBB_SUPPRESS_DEPRECATED_MESSAGES // supress warning 12 | #define TBB_SUPPRESS_DEPRECATED_MESSAGES 1 13 | #endif 14 | #include "tbb/tbb.h" 15 | #if !defined(TBB_INTERFACE_VERSION) 16 | #error "Unknows/unsupported TBB version" 17 | #endif 18 | 19 | #if TBB_INTERFACE_VERSION >= 8000 20 | #include "tbb/task_arena.h" 21 | #endif 22 | 23 | namespace cv { namespace parallel { namespace tbb { 24 | 25 | using namespace ::tbb; 26 | 27 | #if TBB_INTERFACE_VERSION >= 8000 28 | static tbb::task_arena& getArena() 29 | { 30 | static tbb::task_arena tbbArena(tbb::task_arena::automatic); 31 | return tbbArena; 32 | } 33 | #else 34 | static tbb::task_scheduler_init& getScheduler() 35 | { 36 | static tbb::task_scheduler_init tbbScheduler(tbb::task_scheduler_init::deferred); 37 | return tbbScheduler; 38 | } 39 | #endif 40 | 41 | /** TBB parallel_for API implementation 42 | * 43 | * @sa setParallelForBackend 44 | * @ingroup core_parallel_backend 45 | */ 46 | class ParallelForBackend : public ParallelForAPI 47 | { 48 | protected: 49 | int numThreads; 50 | int numThreadsMax; 51 | public: 52 | ParallelForBackend() 53 | { 54 | CV_LOG_INFO(NULL, "Initializing TBB parallel backend: TBB_INTERFACE_VERSION=" << TBB_INTERFACE_VERSION); 55 | numThreads = 0; 56 | #if TBB_INTERFACE_VERSION >= 8000 57 | (void)getArena(); 58 | #else 59 | (void)getScheduler(); 60 | #endif 61 | } 62 | 63 | virtual ~ParallelForBackend() {} 64 | 65 | class CallbackProxy 66 | { 67 | const FN_parallel_for_body_cb_t& callback; 68 | void* const callback_data; 69 | const int tasks; 70 | public: 71 | inline CallbackProxy(int tasks_, FN_parallel_for_body_cb_t& callback_, void* callback_data_) 72 | : callback(callback_), callback_data(callback_data_), tasks(tasks_) 73 | { 74 | // nothing 75 | } 76 | 77 | void operator()(const tbb::blocked_range& range) const 78 | { 79 | this->callback(range.begin(), range.end(), callback_data); 80 | } 81 | 82 | void operator()() const 83 | { 84 | tbb::parallel_for(tbb::blocked_range(0, tasks), *this); 85 | } 86 | }; 87 | 88 | virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void* callback_data) CV_OVERRIDE 89 | { 90 | CallbackProxy task(tasks, body_callback, callback_data); 91 | #if TBB_INTERFACE_VERSION >= 8000 92 | getArena().execute(task); 93 | #else 94 | task(); 95 | #endif 96 | } 97 | 98 | virtual int getThreadNum() const CV_OVERRIDE 99 | { 100 | #if TBB_INTERFACE_VERSION >= 9100 101 | return tbb::this_task_arena::current_thread_index(); 102 | #elif TBB_INTERFACE_VERSION >= 8000 103 | return tbb::task_arena::current_thread_index(); 104 | #else 105 | return 0; 106 | #endif 107 | } 108 | 109 | virtual int getNumThreads() const CV_OVERRIDE 110 | { 111 | #if TBB_INTERFACE_VERSION >= 9100 112 | return getArena().max_concurrency(); 113 | #elif TBB_INTERFACE_VERSION >= 8000 114 | return numThreads > 0 115 | ? numThreads 116 | : tbb::task_scheduler_init::default_num_threads(); 117 | #else 118 | return getScheduler().is_active() 119 | ? numThreads 120 | : tbb::task_scheduler_init::default_num_threads(); 121 | #endif 122 | } 123 | 124 | virtual int setNumThreads(int nThreads) CV_OVERRIDE 125 | { 126 | int oldNumThreads = numThreads; 127 | numThreads = nThreads; 128 | 129 | #if TBB_INTERFACE_VERSION >= 8000 130 | auto& tbbArena = getArena(); 131 | if (tbbArena.is_active()) 132 | tbbArena.terminate(); 133 | if (numThreads > 0) 134 | tbbArena.initialize(numThreads); 135 | #else 136 | auto& tbbScheduler = getScheduler(); 137 | if (tbbScheduler.is_active()) 138 | tbbScheduler.terminate(); 139 | if (numThreads > 0) 140 | tbbScheduler.initialize(numThreads); 141 | #endif 142 | return oldNumThreads; 143 | } 144 | 145 | const char* getName() const CV_OVERRIDE 146 | { 147 | return "tbb"; 148 | } 149 | }; 150 | 151 | }}} // namespace 152 | 153 | #endif // OPENCV_CORE_PARALLEL_FOR_TBB_HPP 154 | -------------------------------------------------------------------------------- /opencv/opencv2/core/parallel/parallel_backend.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_PARALLEL_BACKEND_HPP 6 | #define OPENCV_CORE_PARALLEL_BACKEND_HPP 7 | 8 | #include "opencv2/core/cvdef.h" 9 | #include 10 | 11 | namespace cv { namespace parallel { 12 | #ifndef CV_API_CALL 13 | #define CV_API_CALL 14 | #endif 15 | 16 | /** @addtogroup core_parallel_backend 17 | * @{ 18 | * API below is provided to resolve problem of CPU resource over-subscription by multiple thread pools from different multi-threading frameworks. 19 | * This is common problem for cases when OpenCV compiled threading framework is different from the Users Applications framework. 20 | * 21 | * Applications can replace OpenCV `parallel_for()` backend with own implementation (to reuse Application's thread pool). 22 | * 23 | * 24 | * ### Backend API usage examples 25 | * 26 | * #### Intel TBB 27 | * 28 | * - include header with simple implementation of TBB backend: 29 | * @snippet parallel_backend/example-tbb.cpp tbb_include 30 | * - execute backend replacement code: 31 | * @snippet parallel_backend/example-tbb.cpp tbb_backend 32 | * - configuration of compiler/linker options is responsibility of Application's scripts 33 | * 34 | * #### OpenMP 35 | * 36 | * - include header with simple implementation of OpenMP backend: 37 | * @snippet parallel_backend/example-openmp.cpp openmp_include 38 | * - execute backend replacement code: 39 | * @snippet parallel_backend/example-openmp.cpp openmp_backend 40 | * - Configuration of compiler/linker options is responsibility of Application's scripts 41 | * 42 | * 43 | * ### Plugins support 44 | * 45 | * Runtime configuration options: 46 | * - change backend priority: `OPENCV_PARALLEL_PRIORITY_=9999` 47 | * - disable backend: `OPENCV_PARALLEL_PRIORITY_=0` 48 | * - specify list of backends with high priority (>100000): `OPENCV_PARALLEL_PRIORITY_LIST=TBB,OPENMP`. Unknown backends are registered as new plugins. 49 | * 50 | */ 51 | 52 | /** Interface for parallel_for backends implementations 53 | * 54 | * @sa setParallelForBackend 55 | */ 56 | class CV_EXPORTS ParallelForAPI 57 | { 58 | public: 59 | virtual ~ParallelForAPI(); 60 | 61 | typedef void (CV_API_CALL *FN_parallel_for_body_cb_t)(int start, int end, void* data); 62 | 63 | virtual void parallel_for(int tasks, FN_parallel_for_body_cb_t body_callback, void* callback_data) = 0; 64 | 65 | virtual int getThreadNum() const = 0; 66 | 67 | virtual int getNumThreads() const = 0; 68 | 69 | virtual int setNumThreads(int nThreads) = 0; 70 | 71 | virtual const char* getName() const = 0; 72 | }; 73 | 74 | /** @brief Replace OpenCV parallel_for backend 75 | * 76 | * Application can replace OpenCV `parallel_for()` backend with own implementation. 77 | * 78 | * @note This call is not thread-safe. Consider calling this function from the `main()` before any other OpenCV processing functions (and without any other created threads). 79 | */ 80 | CV_EXPORTS void setParallelForBackend(const std::shared_ptr& api, bool propagateNumThreads = true); 81 | 82 | /** @brief Change OpenCV parallel_for backend 83 | * 84 | * @note This call is not thread-safe. Consider calling this function from the `main()` before any other OpenCV processing functions (and without any other created threads). 85 | */ 86 | CV_EXPORTS_W bool setParallelForBackend(const std::string& backendName, bool propagateNumThreads = true); 87 | 88 | //! @} 89 | }} // namespace 90 | #endif // OPENCV_CORE_PARALLEL_BACKEND_HPP 91 | -------------------------------------------------------------------------------- /opencv/opencv2/core/simd_intrinsics.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_SIMD_INTRINSICS_HPP 6 | #define OPENCV_CORE_SIMD_INTRINSICS_HPP 7 | 8 | /** 9 | Helper header to support SIMD intrinsics (universal intrinsics) in user code. 10 | Intrinsics documentation: https://docs.opencv.org/4.x/df/d91/group__core__hal__intrin.html 11 | 12 | 13 | Checks of target CPU instruction set based on compiler definitions don't work well enough. 14 | More reliable solutions require utilization of configuration systems (like CMake). 15 | 16 | So, probably you need to specify your own configuration. 17 | 18 | You can do that via CMake in this way: 19 | add_definitions(/DOPENCV_SIMD_CONFIG_HEADER=opencv_simd_config_custom.hpp) 20 | or 21 | add_definitions(/DOPENCV_SIMD_CONFIG_INCLUDE_DIR=1) 22 | 23 | Additionally you may need to add include directory to your files: 24 | include_directories("${CMAKE_CURRENT_LIST_DIR}/opencv_config_${MYTARGET}") 25 | 26 | These files can be pre-generated for target configurations of your application 27 | or generated by CMake on the fly (use CMAKE_BINARY_DIR for that). 28 | 29 | Notes: 30 | - H/W capability checks are still responsibility of your application 31 | - runtime dispatching is not covered by this helper header 32 | */ 33 | 34 | #ifdef __OPENCV_BUILD 35 | #error "Use core/hal/intrin.hpp during OpenCV build" 36 | #endif 37 | 38 | #ifdef OPENCV_HAL_INTRIN_HPP 39 | #error "core/simd_intrinsics.hpp must be included before core/hal/intrin.hpp" 40 | #endif 41 | 42 | #include "opencv2/core/cvdef.h" 43 | 44 | #ifdef OPENCV_SIMD_CONFIG_HEADER 45 | #include CVAUX_STR(OPENCV_SIMD_CONFIG_HEADER) 46 | #elif defined(OPENCV_SIMD_CONFIG_INCLUDE_DIR) 47 | #include "opencv_simd_config.hpp" // corresponding directory should be added via -I compiler parameter 48 | #else // custom config headers 49 | 50 | #if (!defined(CV_AVX_512F) || !CV_AVX_512F) && (defined(__AVX512__) || defined(__AVX512F__)) 51 | # include 52 | # undef CV_AVX_512F 53 | # define CV_AVX_512F 1 54 | # ifndef OPENCV_SIMD_DONT_ASSUME_SKX // Skylake-X with AVX-512F/CD/BW/DQ/VL 55 | # undef CV_AVX512_SKX 56 | # define CV_AVX512_SKX 1 57 | # undef CV_AVX_512CD 58 | # define CV_AVX_512CD 1 59 | # undef CV_AVX_512BW 60 | # define CV_AVX_512BW 1 61 | # undef CV_AVX_512DQ 62 | # define CV_AVX_512DQ 1 63 | # undef CV_AVX_512VL 64 | # define CV_AVX_512VL 1 65 | # endif 66 | #endif // AVX512 67 | 68 | // GCC/Clang: -mavx2 69 | // MSVC: /arch:AVX2 70 | #if defined __AVX2__ 71 | # include 72 | # undef CV_AVX2 73 | # define CV_AVX2 1 74 | # if defined __F16C__ 75 | # undef CV_FP16 76 | # define CV_FP16 1 77 | # endif 78 | #endif 79 | 80 | #endif 81 | 82 | // SSE / NEON / VSX is handled by cv_cpu_dispatch.h compatibility block 83 | #include "cv_cpu_dispatch.h" 84 | 85 | #include "hal/intrin.hpp" 86 | 87 | #endif // OPENCV_CORE_SIMD_INTRINSICS_HPP 88 | -------------------------------------------------------------------------------- /opencv/opencv2/core/utils/allocator_stats.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_ALLOCATOR_STATS_HPP 6 | #define OPENCV_CORE_ALLOCATOR_STATS_HPP 7 | 8 | #include "../cvdef.h" 9 | 10 | namespace cv { namespace utils { 11 | 12 | class AllocatorStatisticsInterface 13 | { 14 | protected: 15 | AllocatorStatisticsInterface() {} 16 | virtual ~AllocatorStatisticsInterface() {} 17 | public: 18 | virtual uint64_t getCurrentUsage() const = 0; 19 | virtual uint64_t getTotalUsage() const = 0; 20 | virtual uint64_t getNumberOfAllocations() const = 0; 21 | virtual uint64_t getPeakUsage() const = 0; 22 | 23 | /** set peak usage = current usage */ 24 | virtual void resetPeakUsage() = 0; 25 | }; 26 | 27 | }} // namespace 28 | 29 | #endif // OPENCV_CORE_ALLOCATOR_STATS_HPP 30 | -------------------------------------------------------------------------------- /opencv/opencv2/core/utils/allocator_stats.impl.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP 6 | #define OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP 7 | 8 | #include "./allocator_stats.hpp" 9 | 10 | //#define OPENCV_DISABLE_ALLOCATOR_STATS 11 | 12 | #include 13 | 14 | #ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE 15 | #if defined(__GNUC__) && (\ 16 | (defined(__SIZEOF_POINTER__) && __SIZEOF_POINTER__ == 4) || \ 17 | (defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)) \ 18 | ) 19 | #define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE int 20 | #endif 21 | #endif 22 | 23 | #ifndef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE 24 | #define OPENCV_ALLOCATOR_STATS_COUNTER_TYPE long long 25 | #endif 26 | 27 | namespace cv { namespace utils { 28 | 29 | #ifdef CV__ALLOCATOR_STATS_LOG 30 | namespace { 31 | #endif 32 | 33 | class AllocatorStatistics : public AllocatorStatisticsInterface 34 | { 35 | #ifdef OPENCV_DISABLE_ALLOCATOR_STATS 36 | 37 | public: 38 | AllocatorStatistics() {} 39 | ~AllocatorStatistics() CV_OVERRIDE {} 40 | 41 | uint64_t getCurrentUsage() const CV_OVERRIDE { return 0; } 42 | uint64_t getTotalUsage() const CV_OVERRIDE { return 0; } 43 | uint64_t getNumberOfAllocations() const CV_OVERRIDE { return 0; } 44 | uint64_t getPeakUsage() const CV_OVERRIDE { return 0; } 45 | 46 | /** set peak usage = current usage */ 47 | void resetPeakUsage() CV_OVERRIDE {}; 48 | 49 | void onAllocate(size_t /*sz*/) {} 50 | void onFree(size_t /*sz*/) {} 51 | 52 | #else 53 | 54 | protected: 55 | typedef OPENCV_ALLOCATOR_STATS_COUNTER_TYPE counter_t; 56 | std::atomic curr, total, total_allocs, peak; 57 | public: 58 | AllocatorStatistics() {} 59 | ~AllocatorStatistics() CV_OVERRIDE {} 60 | 61 | uint64_t getCurrentUsage() const CV_OVERRIDE { return (uint64_t)curr.load(); } 62 | uint64_t getTotalUsage() const CV_OVERRIDE { return (uint64_t)total.load(); } 63 | uint64_t getNumberOfAllocations() const CV_OVERRIDE { return (uint64_t)total_allocs.load(); } 64 | uint64_t getPeakUsage() const CV_OVERRIDE { return (uint64_t)peak.load(); } 65 | 66 | /** set peak usage = current usage */ 67 | void resetPeakUsage() CV_OVERRIDE { peak.store(curr.load()); } 68 | 69 | // Controller interface 70 | void onAllocate(size_t sz) 71 | { 72 | #ifdef CV__ALLOCATOR_STATS_LOG 73 | CV__ALLOCATOR_STATS_LOG(cv::format("allocate: %lld (curr=%lld)", (long long int)sz, (long long int)curr.load())); 74 | #endif 75 | 76 | counter_t new_curr = curr.fetch_add((counter_t)sz) + (counter_t)sz; 77 | 78 | // peak = std::max((uint64_t)peak, new_curr); 79 | auto prev_peak = peak.load(); 80 | while (prev_peak < new_curr) 81 | { 82 | if (peak.compare_exchange_weak(prev_peak, new_curr)) 83 | break; 84 | } 85 | // end of peak = max(...) 86 | 87 | total += (counter_t)sz; 88 | total_allocs++; 89 | } 90 | void onFree(size_t sz) 91 | { 92 | #ifdef CV__ALLOCATOR_STATS_LOG 93 | CV__ALLOCATOR_STATS_LOG(cv::format("free: %lld (curr=%lld)", (long long int)sz, (long long int)curr.load())); 94 | #endif 95 | curr -= (counter_t)sz; 96 | } 97 | #endif // OPENCV_DISABLE_ALLOCATOR_STATS 98 | }; 99 | 100 | #ifdef CV__ALLOCATOR_STATS_LOG 101 | } // namespace 102 | #endif 103 | 104 | }} // namespace 105 | 106 | #endif // OPENCV_CORE_ALLOCATOR_STATS_IMPL_HPP 107 | -------------------------------------------------------------------------------- /opencv/opencv2/core/utils/filesystem.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_UTILS_FILESYSTEM_HPP 6 | #define OPENCV_UTILS_FILESYSTEM_HPP 7 | 8 | namespace cv { namespace utils { namespace fs { 9 | 10 | 11 | CV_EXPORTS bool exists(const cv::String& path); 12 | CV_EXPORTS bool isDirectory(const cv::String& path); 13 | 14 | CV_EXPORTS void remove_all(const cv::String& path); 15 | 16 | 17 | CV_EXPORTS cv::String getcwd(); 18 | 19 | /** @brief Converts path p to a canonical absolute path 20 | * Symlinks are processed if there is support for them on running platform. 21 | * 22 | * @param path input path. Target file/directory should exist. 23 | */ 24 | CV_EXPORTS cv::String canonical(const cv::String& path); 25 | 26 | /** Join path components */ 27 | CV_EXPORTS cv::String join(const cv::String& base, const cv::String& path); 28 | 29 | /** Get parent directory */ 30 | CV_EXPORTS cv::String getParent(const cv::String &path); 31 | CV_EXPORTS std::wstring getParent(const std::wstring& path); 32 | 33 | /** 34 | * Generate a list of all files that match the globbing pattern. 35 | * 36 | * Result entries are prefixed by base directory path. 37 | * 38 | * @param directory base directory 39 | * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results 40 | * @param[out] result result of globing. 41 | * @param recursive scan nested directories too 42 | * @param includeDirectories include directories into results list 43 | */ 44 | CV_EXPORTS void glob(const cv::String& directory, const cv::String& pattern, 45 | CV_OUT std::vector& result, 46 | bool recursive = false, bool includeDirectories = false); 47 | 48 | /** 49 | * Generate a list of all files that match the globbing pattern. 50 | * 51 | * @param directory base directory 52 | * @param pattern filter pattern (based on '*'/'?' symbols). Use empty string to disable filtering and return all results 53 | * @param[out] result globbing result with relative paths from base directory 54 | * @param recursive scan nested directories too 55 | * @param includeDirectories include directories into results list 56 | */ 57 | CV_EXPORTS void glob_relative(const cv::String& directory, const cv::String& pattern, 58 | CV_OUT std::vector& result, 59 | bool recursive = false, bool includeDirectories = false); 60 | 61 | 62 | CV_EXPORTS bool createDirectory(const cv::String& path); 63 | CV_EXPORTS bool createDirectories(const cv::String& path); 64 | 65 | #if defined(__OPENCV_BUILD) || defined(BUILD_PLUGIN) 66 | // TODO 67 | //CV_EXPORTS cv::String getTempDirectory(); 68 | 69 | /** 70 | * @brief Returns directory to store OpenCV cache files 71 | * Create sub-directory in common OpenCV cache directory if it doesn't exist. 72 | * @param sub_directory_name name of sub-directory. NULL or "" value asks to return root cache directory. 73 | * @param configuration_name optional name of configuration parameter name which overrides default behavior. 74 | * @return Path to cache directory. Returns empty string if cache directories support is not available. Returns "disabled" if cache disabled by user. 75 | */ 76 | CV_EXPORTS cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name = NULL); 77 | 78 | #endif 79 | 80 | }}} // namespace 81 | 82 | #endif // OPENCV_UTILS_FILESYSTEM_HPP 83 | -------------------------------------------------------------------------------- /opencv/opencv2/core/utils/fp_control_utils.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_FP_CONTROL_UTILS_HPP 6 | #define OPENCV_CORE_FP_CONTROL_UTILS_HPP 7 | 8 | namespace cv { 9 | 10 | namespace details { 11 | 12 | struct FPDenormalsModeState 13 | { 14 | uint32_t reserved[16]; // 64-bytes 15 | }; // FPDenormalsModeState 16 | 17 | CV_EXPORTS void setFPDenormalsIgnoreHint(bool ignore, CV_OUT FPDenormalsModeState& state); 18 | CV_EXPORTS int saveFPDenormalsState(CV_OUT FPDenormalsModeState& state); 19 | CV_EXPORTS bool restoreFPDenormalsState(const FPDenormalsModeState& state); 20 | 21 | class FPDenormalsIgnoreHintScope 22 | { 23 | public: 24 | inline explicit FPDenormalsIgnoreHintScope(bool ignore = true) 25 | { 26 | details::setFPDenormalsIgnoreHint(ignore, saved_state); 27 | } 28 | 29 | inline explicit FPDenormalsIgnoreHintScope(const FPDenormalsModeState& state) 30 | { 31 | details::saveFPDenormalsState(saved_state); 32 | details::restoreFPDenormalsState(state); 33 | } 34 | 35 | inline ~FPDenormalsIgnoreHintScope() 36 | { 37 | details::restoreFPDenormalsState(saved_state); 38 | } 39 | 40 | protected: 41 | FPDenormalsModeState saved_state; 42 | }; // FPDenormalsIgnoreHintScope 43 | 44 | class FPDenormalsIgnoreHintScopeNOOP 45 | { 46 | public: 47 | inline FPDenormalsIgnoreHintScopeNOOP(bool ignore = true) { CV_UNUSED(ignore); } 48 | inline FPDenormalsIgnoreHintScopeNOOP(const FPDenormalsModeState& state) { CV_UNUSED(state); } 49 | inline ~FPDenormalsIgnoreHintScopeNOOP() { } 50 | }; // FPDenormalsIgnoreHintScopeNOOP 51 | 52 | } // namespace details 53 | 54 | 55 | // Should depend on target compilation architecture only 56 | // Note: previously added archs should NOT be removed to preserve ABI compatibility 57 | #if defined(OPENCV_SUPPORTS_FP_DENORMALS_HINT) 58 | // preserve configuration overloading through ports 59 | #elif defined(__i386__) || defined(__x86_64__) || defined(_M_X64) || defined(_X86_) 60 | typedef details::FPDenormalsIgnoreHintScope FPDenormalsIgnoreHintScope; 61 | #define OPENCV_SUPPORTS_FP_DENORMALS_HINT 1 62 | #else 63 | #define OPENCV_SUPPORTS_FP_DENORMALS_HINT 0 64 | typedef details::FPDenormalsIgnoreHintScopeNOOP FPDenormalsIgnoreHintScope; 65 | #endif 66 | 67 | } // namespace cv 68 | 69 | #endif // OPENCV_CORE_FP_CONTROL_UTILS_HPP 70 | -------------------------------------------------------------------------------- /opencv/opencv2/core/utils/instrumentation.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_UTILS_INSTR_HPP 6 | #define OPENCV_UTILS_INSTR_HPP 7 | 8 | #include 9 | #include 10 | 11 | namespace cv { 12 | 13 | //! @addtogroup core_utils 14 | //! @{ 15 | 16 | #ifdef CV_COLLECT_IMPL_DATA 17 | CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays 18 | CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays 19 | // Get stored implementation flags and functions names arrays 20 | // Each implementation entry correspond to function name entry, so you can find which implementation was executed in which function 21 | CV_EXPORTS int getImpl(std::vector &impl, std::vector &funName); 22 | 23 | CV_EXPORTS bool useCollection(); // return implementation collection state 24 | CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state 25 | 26 | #define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation 27 | #define CV_IMPL_OCL 0x02 // OpenCL implementation 28 | #define CV_IMPL_IPP 0x04 // IPP implementation 29 | #define CV_IMPL_MT 0x10 // multithreaded implementation 30 | 31 | #undef CV_IMPL_ADD 32 | #define CV_IMPL_ADD(impl) \ 33 | if(cv::useCollection()) \ 34 | { \ 35 | cv::addImpl(impl, CV_Func); \ 36 | } 37 | #endif 38 | 39 | // Instrumentation external interface 40 | namespace instr 41 | { 42 | 43 | #if !defined OPENCV_ABI_CHECK 44 | 45 | enum TYPE 46 | { 47 | TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function 48 | TYPE_MARKER, // Information marker 49 | TYPE_WRAPPER, // Wrapper function for implementation 50 | TYPE_FUN, // Simple function call 51 | }; 52 | 53 | enum IMPL 54 | { 55 | IMPL_PLAIN = 0, 56 | IMPL_IPP, 57 | IMPL_OPENCL, 58 | }; 59 | 60 | struct NodeDataTls 61 | { 62 | NodeDataTls() 63 | { 64 | m_ticksTotal = 0; 65 | } 66 | uint64 m_ticksTotal; 67 | }; 68 | 69 | class CV_EXPORTS NodeData 70 | { 71 | public: 72 | NodeData(const char* funName = 0, const char* fileName = NULL, int lineNum = 0, void* retAddress = NULL, bool alwaysExpand = false, cv::instr::TYPE instrType = TYPE_GENERAL, cv::instr::IMPL implType = IMPL_PLAIN); 73 | NodeData(NodeData &ref); 74 | ~NodeData(); 75 | NodeData& operator=(const NodeData&); 76 | 77 | cv::String m_funName; 78 | cv::instr::TYPE m_instrType; 79 | cv::instr::IMPL m_implType; 80 | const char* m_fileName; 81 | int m_lineNum; 82 | void* m_retAddress; 83 | bool m_alwaysExpand; 84 | bool m_funError; 85 | 86 | volatile int m_counter; 87 | volatile uint64 m_ticksTotal; 88 | TLSDataAccumulator m_tls; 89 | int m_threads; 90 | 91 | // No synchronization 92 | double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; } 93 | double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; } 94 | }; 95 | bool operator==(const NodeData& lhs, const NodeData& rhs); 96 | 97 | typedef Node InstrNode; 98 | 99 | CV_EXPORTS InstrNode* getTrace(); 100 | 101 | #endif // !defined OPENCV_ABI_CHECK 102 | 103 | 104 | CV_EXPORTS bool useInstrumentation(); 105 | CV_EXPORTS void setUseInstrumentation(bool flag); 106 | CV_EXPORTS void resetTrace(); 107 | 108 | enum FLAGS 109 | { 110 | FLAGS_NONE = 0, 111 | FLAGS_MAPPING = 0x01, 112 | FLAGS_EXPAND_SAME_NAMES = 0x02, 113 | }; 114 | 115 | CV_EXPORTS void setFlags(FLAGS modeFlags); 116 | static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); } 117 | CV_EXPORTS FLAGS getFlags(); 118 | 119 | } // namespace instr 120 | 121 | //! @} 122 | 123 | } // namespace 124 | 125 | #endif // OPENCV_UTILS_TLS_HPP 126 | -------------------------------------------------------------------------------- /opencv/opencv2/core/utils/logger.defines.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_LOGGER_DEFINES_HPP 6 | #define OPENCV_LOGGER_DEFINES_HPP 7 | 8 | //! @addtogroup core_logging 9 | //! @{ 10 | 11 | // Supported logging levels and their semantic 12 | #define CV_LOG_LEVEL_SILENT 0 //!< for using in setLogLevel() call 13 | #define CV_LOG_LEVEL_FATAL 1 //!< Fatal (critical) error (unrecoverable internal error) 14 | #define CV_LOG_LEVEL_ERROR 2 //!< Error message 15 | #define CV_LOG_LEVEL_WARN 3 //!< Warning message 16 | #define CV_LOG_LEVEL_INFO 4 //!< Info message 17 | #define CV_LOG_LEVEL_DEBUG 5 //!< Debug message. Disabled in the "Release" build. 18 | #define CV_LOG_LEVEL_VERBOSE 6 //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. 19 | 20 | namespace cv { 21 | namespace utils { 22 | namespace logging { 23 | 24 | //! Supported logging levels and their semantic 25 | enum LogLevel { 26 | LOG_LEVEL_SILENT = 0, //!< for using in setLogVevel() call 27 | LOG_LEVEL_FATAL = 1, //!< Fatal (critical) error (unrecoverable internal error) 28 | LOG_LEVEL_ERROR = 2, //!< Error message 29 | LOG_LEVEL_WARNING = 3, //!< Warning message 30 | LOG_LEVEL_INFO = 4, //!< Info message 31 | LOG_LEVEL_DEBUG = 5, //!< Debug message. Disabled in the "Release" build. 32 | LOG_LEVEL_VERBOSE = 6, //!< Verbose (trace) messages. Requires verbosity level. Disabled in the "Release" build. 33 | #ifndef CV_DOXYGEN 34 | ENUM_LOG_LEVEL_FORCE_INT = INT_MAX 35 | #endif 36 | }; 37 | 38 | }}} // namespace 39 | 40 | //! @} 41 | 42 | #endif // OPENCV_LOGGER_DEFINES_HPP 43 | -------------------------------------------------------------------------------- /opencv/opencv2/core/utils/logtag.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_CORE_LOGTAG_HPP 6 | #define OPENCV_CORE_LOGTAG_HPP 7 | 8 | #include "opencv2/core/cvstd.hpp" 9 | #include "logger.defines.hpp" 10 | 11 | namespace cv { 12 | namespace utils { 13 | namespace logging { 14 | 15 | struct LogTag 16 | { 17 | const char* name; 18 | LogLevel level; 19 | 20 | inline LogTag(const char* _name, LogLevel _level) 21 | : name(_name) 22 | , level(_level) 23 | {} 24 | }; 25 | 26 | }}} 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /opencv/opencv2/core/va_intel.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | // Copyright (C) 2015, Itseez, Inc., all rights reserved. 6 | // Third party copyrights are property of their respective owners. 7 | 8 | #ifndef OPENCV_CORE_VA_INTEL_HPP 9 | #define OPENCV_CORE_VA_INTEL_HPP 10 | 11 | #ifndef __cplusplus 12 | # error va_intel.hpp header must be compiled as C++ 13 | #endif 14 | 15 | #include "opencv2/core.hpp" 16 | #include "ocl.hpp" 17 | 18 | #if defined(HAVE_VA) 19 | # include "va/va.h" 20 | #else // HAVE_VA 21 | # if !defined(_VA_H_) 22 | typedef void* VADisplay; 23 | typedef unsigned int VASurfaceID; 24 | # endif // !_VA_H_ 25 | #endif // HAVE_VA 26 | 27 | namespace cv { namespace va_intel { 28 | 29 | /** @addtogroup core_va_intel 30 | This section describes Intel VA-API/OpenCL (CL-VA) interoperability. 31 | 32 | To enable basic VA interoperability build OpenCV with libva library integration enabled: `-DWITH_VA=ON` (corresponding dev package should be installed). 33 | 34 | To enable advanced CL-VA interoperability support on Intel HW, enable option: `-DWITH_VA_INTEL=ON` (OpenCL integration should be enabled which is the default setting). Special runtime environment should be set up in order to use this feature: correct combination of [libva](https://github.com/intel/libva), [OpenCL runtime](https://github.com/intel/compute-runtime) and [media driver](https://github.com/intel/media-driver) should be installed. 35 | 36 | Check usage example for details: samples/va_intel/va_intel_interop.cpp 37 | */ 38 | //! @{ 39 | 40 | /////////////////// CL-VA Interoperability Functions /////////////////// 41 | 42 | namespace ocl { 43 | using namespace cv::ocl; 44 | 45 | // TODO static functions in the Context class 46 | /** @brief Creates OpenCL context from VA. 47 | @param display - VADisplay for which CL interop should be established. 48 | @param tryInterop - try to set up for interoperability, if true; set up for use slow copy if false. 49 | @return Returns reference to OpenCL Context 50 | */ 51 | CV_EXPORTS Context& initializeContextFromVA(VADisplay display, bool tryInterop = true); 52 | 53 | } // namespace cv::va_intel::ocl 54 | 55 | /** @brief Converts InputArray to VASurfaceID object. 56 | @param display - VADisplay object. 57 | @param src - source InputArray. 58 | @param surface - destination VASurfaceID object. 59 | @param size - size of image represented by VASurfaceID object. 60 | */ 61 | CV_EXPORTS void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface, Size size); 62 | 63 | /** @brief Converts VASurfaceID object to OutputArray. 64 | @param display - VADisplay object. 65 | @param surface - source VASurfaceID object. 66 | @param size - size of image represented by VASurfaceID object. 67 | @param dst - destination OutputArray. 68 | */ 69 | CV_EXPORTS void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, OutputArray dst); 70 | 71 | //! @} 72 | 73 | }} // namespace cv::va_intel 74 | 75 | #endif /* OPENCV_CORE_VA_INTEL_HPP */ 76 | -------------------------------------------------------------------------------- /opencv/opencv2/core/version.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_VERSION_HPP 6 | #define OPENCV_VERSION_HPP 7 | 8 | #define CV_VERSION_MAJOR 4 9 | #define CV_VERSION_MINOR 10 10 | #define CV_VERSION_REVISION 0 11 | #define CV_VERSION_STATUS "" 12 | 13 | #define CVAUX_STR_EXP(__A) #__A 14 | #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) 15 | 16 | #define CVAUX_STRW_EXP(__A) L ## #__A 17 | #define CVAUX_STRW(__A) CVAUX_STRW_EXP(__A) 18 | 19 | #define CV_VERSION CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS 20 | 21 | /* old style version constants*/ 22 | #define CV_MAJOR_VERSION CV_VERSION_MAJOR 23 | #define CV_MINOR_VERSION CV_VERSION_MINOR 24 | #define CV_SUBMINOR_VERSION CV_VERSION_REVISION 25 | 26 | #endif // OPENCV_VERSION_HPP 27 | -------------------------------------------------------------------------------- /opencv/opencv2/cvconfig.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENCV_CVCONFIG_H_INCLUDED 2 | #define OPENCV_CVCONFIG_H_INCLUDED 3 | 4 | /* OpenCV compiled as static or dynamic libs */ 5 | #define BUILD_SHARED_LIBS 6 | 7 | /* OpenCV intrinsics optimized code */ 8 | #define CV_ENABLE_INTRINSICS 9 | 10 | /* OpenCV additional optimized code */ 11 | /* #undef CV_DISABLE_OPTIMIZATION */ 12 | 13 | /* Compile for 'real' NVIDIA GPU architectures */ 14 | #define CUDA_ARCH_BIN "" 15 | 16 | /* NVIDIA GPU features are used */ 17 | #define CUDA_ARCH_FEATURES "" 18 | 19 | /* Compile for 'virtual' NVIDIA PTX architectures */ 20 | #define CUDA_ARCH_PTX "" 21 | 22 | /* AMD's Basic Linear Algebra Subprograms Library*/ 23 | /* #undef HAVE_CLAMDBLAS */ 24 | 25 | /* AMD's OpenCL Fast Fourier Transform Library*/ 26 | /* #undef HAVE_CLAMDFFT */ 27 | 28 | /* Clp support */ 29 | /* #undef HAVE_CLP */ 30 | 31 | /* NVIDIA CUDA Runtime API*/ 32 | /* #undef HAVE_CUDA */ 33 | 34 | /* NVIDIA CUDA Basic Linear Algebra Subprograms (BLAS) API*/ 35 | /* #undef HAVE_CUBLAS */ 36 | 37 | /* NVIDIA CUDA Deep Neural Network (cuDNN) API*/ 38 | /* #undef HAVE_CUDNN */ 39 | 40 | /* NVIDIA CUDA Fast Fourier Transform (FFT) API*/ 41 | /* #undef HAVE_CUFFT */ 42 | 43 | /* DirectX */ 44 | /* #undef HAVE_DIRECTX */ 45 | /* #undef HAVE_DIRECTX_NV12 */ 46 | /* #undef HAVE_D3D11 */ 47 | /* #undef HAVE_D3D10 */ 48 | /* #undef HAVE_D3D9 */ 49 | 50 | /* Eigen Matrix & Linear Algebra Library */ 51 | /* #undef HAVE_EIGEN */ 52 | 53 | /* Geospatial Data Abstraction Library */ 54 | /* #undef HAVE_GDAL */ 55 | 56 | /* Halide support */ 57 | /* #undef HAVE_HALIDE */ 58 | 59 | /* Vulkan support */ 60 | /* #undef HAVE_VULKAN */ 61 | 62 | /* Define to 1 if you have the header file. */ 63 | #define HAVE_INTTYPES_H 1 64 | 65 | /* Intel Integrated Performance Primitives */ 66 | /* #undef HAVE_IPP */ 67 | /* #undef HAVE_IPP_ICV */ 68 | /* #undef HAVE_IPP_IW */ 69 | /* #undef HAVE_IPP_IW_LL */ 70 | 71 | /* JPEG-2000 codec */ 72 | #define HAVE_OPENJPEG 73 | /* #undef HAVE_JASPER */ 74 | 75 | /* AVIF codec */ 76 | /* #undef HAVE_AVIF */ 77 | 78 | /* IJG JPEG codec */ 79 | #define HAVE_JPEG 80 | 81 | /* GDCM DICOM codec */ 82 | /* #undef HAVE_GDCM */ 83 | 84 | /* NVIDIA Video Decoding API*/ 85 | /* #undef HAVE_NVCUVID */ 86 | /* #undef HAVE_NVCUVID_HEADER */ 87 | /* #undef HAVE_DYNLINK_NVCUVID_HEADER */ 88 | 89 | /* NVIDIA Video Encoding API*/ 90 | /* #undef HAVE_NVCUVENC */ 91 | 92 | /* OpenCL Support */ 93 | /* #undef HAVE_OPENCL */ 94 | /* #undef HAVE_OPENCL_STATIC */ 95 | /* #undef HAVE_OPENCL_SVM */ 96 | 97 | /* NVIDIA OpenCL D3D Extensions support */ 98 | /* #undef HAVE_OPENCL_D3D11_NV */ 99 | 100 | /* OpenEXR codec */ 101 | /* #undef HAVE_OPENEXR */ 102 | 103 | /* OpenGL support*/ 104 | /* #undef HAVE_OPENGL */ 105 | 106 | /* PNG codec */ 107 | #define HAVE_PNG 108 | 109 | /* PNG codec */ 110 | /* #undef HAVE_SPNG */ 111 | 112 | /* Posix threads (pthreads) */ 113 | #define HAVE_PTHREAD 114 | 115 | /* parallel_for with pthreads */ 116 | /* #undef HAVE_PTHREADS_PF */ 117 | 118 | /* Intel Threading Building Blocks */ 119 | /* #undef HAVE_TBB */ 120 | 121 | /* Ste||ar Group High Performance ParallelX */ 122 | /* #undef HAVE_HPX */ 123 | 124 | /* TIFF codec */ 125 | #define HAVE_TIFF 126 | 127 | /* Define if your processor stores words with the most significant byte 128 | first (like Motorola and SPARC, unlike Intel and VAX). */ 129 | /* #undef WORDS_BIGENDIAN */ 130 | 131 | /* VA library (libva) */ 132 | /* #undef HAVE_VA */ 133 | 134 | /* Intel VA-API/OpenCL */ 135 | /* #undef HAVE_VA_INTEL */ 136 | 137 | /* Lapack */ 138 | /* #undef HAVE_LAPACK */ 139 | 140 | /* Library was compiled with functions instrumentation */ 141 | /* #undef ENABLE_INSTRUMENTATION */ 142 | 143 | /* OpenVX */ 144 | /* #undef HAVE_OPENVX */ 145 | 146 | /* OpenCV trace utilities */ 147 | #define OPENCV_TRACE 148 | 149 | /* Library QR-code decoding */ 150 | /* #undef HAVE_QUIRC */ 151 | 152 | #endif // OPENCV_CVCONFIG_H_INCLUDED 153 | -------------------------------------------------------------------------------- /opencv/opencv2/imgproc/bindings.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html. 4 | 5 | #ifndef OPENCV_IMGPROC_BINDINGS_HPP 6 | #define OPENCV_IMGPROC_BINDINGS_HPP 7 | 8 | // This file contains special overloads for OpenCV bindings 9 | // No need to use these functions in C++ code. 10 | 11 | namespace cv { 12 | 13 | /** @brief Finds lines in a binary image using the standard Hough transform and get accumulator. 14 | * 15 | * @note This function is for bindings use only. Use original function in C++ code 16 | * 17 | * @sa HoughLines 18 | */ 19 | CV_WRAP static inline 20 | void HoughLinesWithAccumulator( 21 | InputArray image, OutputArray lines, 22 | double rho, double theta, int threshold, 23 | double srn = 0, double stn = 0, 24 | double min_theta = 0, double max_theta = CV_PI 25 | ) 26 | { 27 | std::vector lines_acc; 28 | HoughLines(image, lines_acc, rho, theta, threshold, srn, stn, min_theta, max_theta); 29 | Mat(lines_acc).copyTo(lines); 30 | } 31 | 32 | } // namespace 33 | 34 | #endif // OPENCV_IMGPROC_BINDINGS_HPP 35 | -------------------------------------------------------------------------------- /opencv/opencv2/imgproc/detail/legacy.hpp: -------------------------------------------------------------------------------- 1 | // This file is part of OpenCV project. 2 | // It is subject to the license terms in the LICENSE file found in the top-level directory 3 | // of this distribution and at http://opencv.org/license.html 4 | 5 | #ifndef OPENCV_IMGPROC_DETAIL_LEGACY_HPP 6 | #define OPENCV_IMGPROC_DETAIL_LEGACY_HPP 7 | 8 | #include "opencv2/imgproc.hpp" 9 | 10 | namespace cv { 11 | 12 | #ifdef __OPENCV_BUILD 13 | 14 | CV_EXPORTS void findContours_legacy(InputArray _image, 15 | OutputArrayOfArrays _contours, 16 | OutputArray _hierarchy, 17 | int mode, 18 | int method, 19 | Point offset = Point()); 20 | CV_EXPORTS void findContours_legacy(InputArray image, 21 | OutputArrayOfArrays contours, 22 | int mode, 23 | int method, 24 | Point offset = Point()); 25 | 26 | CV_EXPORTS float EMD_legacy( InputArray _signature1, InputArray _signature2, 27 | int distType, InputArray _cost, 28 | float* lowerBound, OutputArray _flow ); 29 | 30 | CV_EXPORTS float wrapperEMD_legacy(InputArray _signature1, InputArray _signature2, 31 | int distType, InputArray _cost, 32 | Ptr lowerBound, OutputArray _flow); 33 | 34 | #endif 35 | 36 | } // namespace cv 37 | 38 | #endif // OPENCV_IMGPROC_DETAIL_LEGACY_HPP 39 | -------------------------------------------------------------------------------- /opencv/opencv2/imgproc/hal/interface.h: -------------------------------------------------------------------------------- 1 | #ifndef OPENCV_IMGPROC_HAL_INTERFACE_H 2 | #define OPENCV_IMGPROC_HAL_INTERFACE_H 3 | 4 | //! @addtogroup imgproc_hal_interface 5 | //! @{ 6 | 7 | //! @name Interpolation modes 8 | //! @sa cv::InterpolationFlags 9 | //! @{ 10 | #define CV_HAL_INTER_NEAREST 0 11 | #define CV_HAL_INTER_LINEAR 1 12 | #define CV_HAL_INTER_CUBIC 2 13 | #define CV_HAL_INTER_AREA 3 14 | #define CV_HAL_INTER_LANCZOS4 4 15 | //! @} 16 | 17 | //! @name Morphology operations 18 | //! @sa cv::MorphTypes 19 | //! @{ 20 | #define CV_HAL_MORPH_ERODE 0 21 | #define CV_HAL_MORPH_DILATE 1 22 | //! @} 23 | 24 | //! @name Threshold types 25 | //! @sa cv::ThresholdTypes 26 | //! @{ 27 | #define CV_HAL_THRESH_BINARY 0 28 | #define CV_HAL_THRESH_BINARY_INV 1 29 | #define CV_HAL_THRESH_TRUNC 2 30 | #define CV_HAL_THRESH_TOZERO 3 31 | #define CV_HAL_THRESH_TOZERO_INV 4 32 | #define CV_HAL_THRESH_MASK 7 33 | #define CV_HAL_THRESH_OTSU 8 34 | #define CV_HAL_THRESH_TRIANGLE 16 35 | //! @} 36 | 37 | //! @name Adaptive threshold algorithm 38 | //! @sa cv::AdaptiveThresholdTypes 39 | //! @{ 40 | #define CV_HAL_ADAPTIVE_THRESH_MEAN_C 0 41 | #define CV_HAL_ADAPTIVE_THRESH_GAUSSIAN_C 1 42 | //! @} 43 | 44 | //! @} 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /opencv/opencv2/imgproc/imgproc.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 16 | // Third party copyrights are property of their respective owners. 17 | // 18 | // Redistribution and use in source and binary forms, with or without modification, 19 | // are permitted provided that the following conditions are met: 20 | // 21 | // * Redistribution's of source code must retain the above copyright notice, 22 | // this list of conditions and the following disclaimer. 23 | // 24 | // * Redistribution's in binary form must reproduce the above copyright notice, 25 | // this list of conditions and the following disclaimer in the documentation 26 | // and/or other materials provided with the distribution. 27 | // 28 | // * The name of the copyright holders may not be used to endorse or promote products 29 | // derived from this software without specific prior written permission. 30 | // 31 | // This software is provided by the copyright holders and contributors "as is" and 32 | // any express or implied warranties, including, but not limited to, the implied 33 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 34 | // In no event shall the Intel Corporation or contributors be liable for any direct, 35 | // indirect, incidental, special, exemplary, or consequential damages 36 | // (including, but not limited to, procurement of substitute goods or services; 37 | // loss of use, data, or profits; or business interruption) however caused 38 | // and on any theory of liability, whether in contract, strict liability, 39 | // or tort (including negligence or otherwise) arising in any way out of 40 | // the use of this software, even if advised of the possibility of such damage. 41 | // 42 | //M*/ 43 | 44 | #ifdef __OPENCV_BUILD 45 | #error this is a compatibility header which should not be used inside the OpenCV library 46 | #endif 47 | 48 | #include "opencv2/imgproc.hpp" 49 | -------------------------------------------------------------------------------- /opencv/opencv2/opencv.hpp: -------------------------------------------------------------------------------- 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4 | // 5 | // By downloading, copying, installing or using the software you agree to this license. 6 | // If you do not agree to this license, do not download, install, 7 | // copy or use the software. 8 | // 9 | // 10 | // License Agreement 11 | // For Open Source Computer Vision Library 12 | // 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14 | // Copyright (C) 2009-2010, Willow Garage Inc., all rights reserved. 15 | // Third party copyrights are property of their respective owners. 16 | // 17 | // Redistribution and use in source and binary forms, with or without modification, 18 | // are permitted provided that the following conditions are met: 19 | // 20 | // * Redistribution's of source code must retain the above copyright notice, 21 | // this list of conditions and the following disclaimer. 22 | // 23 | // * Redistribution's in binary form must reproduce the above copyright notice, 24 | // this list of conditions and the following disclaimer in the documentation 25 | // and/or other materials provided with the distribution. 26 | // 27 | // * The name of the copyright holders may not be used to endorse or promote products 28 | // derived from this software without specific prior written permission. 29 | // 30 | // This software is provided by the copyright holders and contributors "as is" and 31 | // any express or implied warranties, including, but not limited to, the implied 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, 34 | // indirect, incidental, special, exemplary, or consequential damages 35 | // (including, but not limited to, procurement of substitute goods or services; 36 | // loss of use, data, or profits; or business interruption) however caused 37 | // and on any theory of liability, whether in contract, strict liability, 38 | // or tort (including negligence or otherwise) arising in any way out of 39 | // the use of this software, even if advised of the possibility of such damage. 40 | // 41 | //M*/ 42 | 43 | #ifndef OPENCV_ALL_HPP 44 | #define OPENCV_ALL_HPP 45 | 46 | // File that defines what modules where included during the build of OpenCV 47 | // These are purely the defines of the correct HAVE_OPENCV_modulename values 48 | #include "opencv2/opencv_modules.hpp" 49 | 50 | // Then the list of defines is checked to include the correct headers 51 | // Core library is always included --> without no OpenCV functionality available 52 | #include "opencv2/core.hpp" 53 | 54 | // Then the optional modules are checked 55 | #ifdef HAVE_OPENCV_IMGPROC 56 | #include "opencv2/imgproc.hpp" 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /opencv/opencv2/opencv_modules.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * ** File generated automatically, do not modify ** 3 | * 4 | * This file defines the list of modules available in current build configuration 5 | * 6 | * 7 | */ 8 | 9 | // This definition means that OpenCV is built with enabled non-free code. 10 | // For example, patented algorithms for non-profit/non-commercial use only. 11 | /* #undef OPENCV_ENABLE_NONFREE */ 12 | 13 | #define HAVE_OPENCV_CORE 14 | #define HAVE_OPENCV_IMGPROC 15 | 16 | 17 | -------------------------------------------------------------------------------- /plugin/plugin.go: -------------------------------------------------------------------------------- 1 | package plugin 2 | 3 | import ( 4 | "fmt" 5 | "github.com/Dasongzi1366/AutoGo/java" 6 | "os" 7 | "strconv" 8 | "strings" 9 | ) 10 | 11 | type Plugin struct { 12 | obj string 13 | apkPath string 14 | } 15 | 16 | type Obj struct { 17 | obj string 18 | } 19 | 20 | type Class struct { 21 | obj string 22 | } 23 | 24 | type Bitmap struct { 25 | Left, Top, Right, Bottom int 26 | } 27 | 28 | type BitmapFromBase64 struct { 29 | Base64 string 30 | } 31 | 32 | type BitmapFromPath struct { 33 | Path string 34 | } 35 | 36 | type AssetManager struct { 37 | ApkPath string 38 | } 39 | 40 | func LoadApk(apkPath string) *Plugin { 41 | _, err := os.Stat(apkPath) 42 | if err != nil { 43 | fmt.Fprintln(os.Stderr, "File "+apkPath+" does not exist.") 44 | os.Exit(1) 45 | } 46 | str := java.CallJavaMethod("plugin", "loadApk|"+apkPath) 47 | if str == "" { 48 | return nil 49 | } 50 | return &Plugin{obj: str, apkPath: apkPath} 51 | } 52 | 53 | func (p *Plugin) NewInstance(className string, values ...interface{}) *Class { 54 | list := "null" 55 | if len(values) > 0 { 56 | list = "" 57 | for _, v := range values { 58 | switch v.(type) { 59 | case string: 60 | list = list + "string@@" + v.(string) + "@@" 61 | case int: 62 | list = list + "int@@" + i2s(v.(int)) + "@@" 63 | case bool: 64 | list = list + "boolean@@" + b2s(v.(bool)) + "@@" 65 | case float32: 66 | list = list + "float@@" + fmt.Sprintf("%f", v.(float32)) + "@@" 67 | case float64: 68 | list = list + "double@@" + strconv.FormatFloat(v.(float64), 'f', -1, 64) + "@@" 69 | case int64: 70 | list = list + "long@@" + strconv.FormatInt(v.(int64), 10) + "@@" 71 | case AssetManager: 72 | list = list + "assetManager@@" + v.(AssetManager).ApkPath + "@@" 73 | case Bitmap: 74 | list = list + "bitmap@@" + i2s(v.(Bitmap).Left) + "," + i2s(v.(Bitmap).Top) + "," + i2s(v.(Bitmap).Right) + "," + i2s(v.(Bitmap).Bottom) + "@@" 75 | case BitmapFromBase64: 76 | list = list + "bitmapbase64@@" + v.(BitmapFromBase64).Base64 + "@@" 77 | case BitmapFromPath: 78 | list = list + "bitmappath@@" + v.(BitmapFromPath).Path + "@@" 79 | default: 80 | panic("Unsupported type: " + fmt.Sprintf("%T", v)) 81 | } 82 | } 83 | list = list[:len(list)-2] 84 | } 85 | str := java.CallJavaMethod("plugin", "newInstance|"+p.obj+"|"+className+"|"+list) 86 | if str == "" { 87 | return nil 88 | } 89 | return &Class{obj: str} 90 | } 91 | 92 | func (c *Class) Call(methodName string, values ...interface{}) *Obj { 93 | list := "null" 94 | if len(values) > 0 { 95 | list = "" 96 | for _, v := range values { 97 | switch v.(type) { 98 | case string: 99 | s := v.(string) 100 | if s == "" { 101 | s = "null" 102 | } 103 | list = list + "string@@" + s + "@@" 104 | case int: 105 | list = list + "int@@" + i2s(v.(int)) + "@@" 106 | case bool: 107 | list = list + "boolean@@" + b2s(v.(bool)) + "@@" 108 | case float32: 109 | list = list + "float@@" + fmt.Sprintf("%f", v.(float32)) + "@@" 110 | case float64: 111 | list = list + "double@@" + strconv.FormatFloat(v.(float64), 'f', -1, 64) + "@@" 112 | case int64: 113 | list = list + "long@@" + strconv.FormatInt(v.(int64), 10) + "@@" 114 | case AssetManager: 115 | list = list + "assetManager@@" + v.(AssetManager).ApkPath + "@@" 116 | case Bitmap: 117 | list = list + "bitmap@@" + i2s(v.(Bitmap).Left) + "," + i2s(v.(Bitmap).Top) + "," + i2s(v.(Bitmap).Right) + "," + i2s(v.(Bitmap).Bottom) + "@@" 118 | case BitmapFromBase64: 119 | list = list + "bitmapbase64@@" + v.(BitmapFromBase64).Base64 + "@@" 120 | case BitmapFromPath: 121 | list = list + "bitmappath@@" + v.(BitmapFromPath).Path + "@@" 122 | default: 123 | panic("Unsupported type: " + fmt.Sprintf("%T", v)) 124 | } 125 | } 126 | list = list[:len(list)-2] 127 | } 128 | return &Obj{obj: java.CallJavaMethod("plugin", "call|"+c.obj+"|"+methodName+"|"+list)} 129 | } 130 | 131 | /*func (o *Obj) Release() { 132 | utils.CallJavaMethod("plugin", "releaseObj|"+o.obj) 133 | o.obj = "" 134 | }*/ 135 | 136 | func (o *Obj) ToString() string { 137 | return o.obj 138 | } 139 | 140 | func (o *Obj) ToInt() int { 141 | return s2i(o.obj) 142 | } 143 | 144 | func (o *Obj) ToBool() bool { 145 | return o.obj == "true" 146 | } 147 | 148 | func (o *Obj) ToInt64() int64 { 149 | if len(o.obj) > 1 { 150 | l, _ := strconv.ParseInt(o.obj, 10, 64) 151 | return l 152 | } 153 | return 0 154 | } 155 | 156 | func (o *Obj) ToFloat32() float32 { 157 | if len(o.obj) > 1 { 158 | f, _ := strconv.ParseFloat(o.obj, 32) 159 | return float32(f) 160 | } 161 | return 0 162 | } 163 | 164 | func s2i(s string) int { 165 | i, _ := strconv.Atoi(strings.TrimSpace(s)) 166 | return i 167 | } 168 | 169 | func i2s(i int) string { 170 | return strconv.Itoa(i) 171 | } 172 | 173 | func b2s(b bool) string { 174 | if b { 175 | return "true" 176 | } 177 | return "false" 178 | } 179 | -------------------------------------------------------------------------------- /ppocr/ppocr.go: -------------------------------------------------------------------------------- 1 | package ppocr 2 | 3 | /* 4 | #include "ppocr.h" 5 | #include 6 | #cgo arm64 LDFLAGS: -L../../resources/libs/arm64-v8a -lopencv_core -lopencv_imgproc -lppocr 7 | #cgo amd64 LDFLAGS: -L../../resources/libs/x86_64 -lopencv_core -lopencv_imgproc -lppocr 8 | #cgo 386 LDFLAGS: -L../../resources/libs/x86 -lopencv_core -lopencv_imgproc -lppocr 9 | */ 10 | import "C" 11 | import ( 12 | "encoding/json" 13 | "fmt" 14 | "os" 15 | "path/filepath" 16 | "strings" 17 | "unsafe" 18 | 19 | "github.com/Dasongzi1366/AutoGo/images" 20 | ) 21 | 22 | type PpOcr struct { 23 | pointer *C.Ppocr 24 | } 25 | 26 | type DetectResult struct { 27 | X int `json:"X"` 28 | Y int `json:"Y"` 29 | Width int `json:"宽"` 30 | Height int `json:"高"` 31 | Label string `json:"标签"` 32 | Score float64 `json:"精度"` 33 | CenterX int `json:"-"` //中心坐标X 34 | CenterY int `json:"-"` //中心坐标Y 35 | } 36 | 37 | func New(cpuThreadNum int) *PpOcr { 38 | pointer := C.newPpocr() 39 | 40 | if pointer == nil { 41 | return nil 42 | } 43 | path := filepath.Dir(os.Args[0]) 44 | 45 | cLabelPath := C.CString(path + "/assets/label.txt") 46 | defer C.free(unsafe.Pointer(cLabelPath)) 47 | 48 | cDbParamPath := C.CString(path + "/assets/db.param") 49 | defer C.free(unsafe.Pointer(cDbParamPath)) 50 | 51 | cDbBinPath := C.CString(path + "/assets/db.bin") 52 | defer C.free(unsafe.Pointer(cDbBinPath)) 53 | 54 | cRecParamPath := C.CString(path + "/assets/rec.param") 55 | defer C.free(unsafe.Pointer(cRecParamPath)) 56 | 57 | cRecBinPath := C.CString(path + "/assets/rec.bin") 58 | defer C.free(unsafe.Pointer(cRecBinPath)) 59 | result := C.loadModelPpocr(pointer, cLabelPath, cDbParamPath, cDbBinPath, cRecParamPath, cRecBinPath, C.int(cpuThreadNum)) 60 | goResult := C.GoString(result) 61 | C.free(unsafe.Pointer(result)) 62 | if goResult != "OK" { 63 | fmt.Println("ppocr:" + goResult) 64 | return nil 65 | } 66 | return &PpOcr{pointer: pointer} 67 | } 68 | 69 | func (p *PpOcr) Detect(x1, y1, x2, y2 int) []DetectResult { 70 | img := images.CaptureScreen(x1, y1, x2, y2) 71 | if img == nil { 72 | return nil 73 | } 74 | 75 | result := C.detectPpocr( 76 | p.pointer, 77 | (*C.uchar)(unsafe.Pointer(&img.Pix[0])), 78 | C.int(img.Rect.Dx()), 79 | C.int(img.Rect.Dy()), 80 | C.float(0.45), 81 | C.float(0.5), 82 | C.int(640), 83 | ) 84 | goResult := C.GoString(result) 85 | C.free(unsafe.Pointer(result)) 86 | 87 | var results []DetectResult 88 | err := json.Unmarshal([]byte(goResult), &results) 89 | if err != nil { 90 | return nil 91 | } 92 | 93 | var validResults []DetectResult 94 | for _, result := range results { 95 | if strings.TrimSpace(result.Label) == "" { 96 | continue 97 | } 98 | result.X += x1 99 | result.Y += y1 100 | result.CenterX = result.X + result.Width/2 101 | result.CenterY = result.Y + result.Height/2 102 | validResults = append(validResults, result) 103 | } 104 | 105 | return validResults 106 | } 107 | 108 | func (p *PpOcr) Close() { 109 | C.closePpocr(p.pointer) 110 | } 111 | -------------------------------------------------------------------------------- /ppocr/ppocr.h: -------------------------------------------------------------------------------- 1 | #ifndef PPOCR_H 2 | #define PPOCR_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct Ppocr Ppocr; 9 | 10 | Ppocr* newPpocr(); 11 | 12 | const char* loadModelPpocr(Ppocr* Obj, const char* label, const char* dbParam, const char* dbBin, const char* recParam, const char* recBin, int thread); 13 | 14 | char* detectPpocr(Ppocr* Obj, const unsigned char* bitmapData, int width, int height, float nms, float prob, int size); 15 | 16 | void closePpocr(Ppocr* Obj); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif // PPOCR_H 23 | -------------------------------------------------------------------------------- /storages/storages.go: -------------------------------------------------------------------------------- 1 | package storages 2 | 3 | import ( 4 | "database/sql" 5 | _ "github.com/mattn/go-sqlite3" 6 | "os" 7 | "path/filepath" 8 | ) 9 | 10 | var database *sql.DB 11 | 12 | func init() { 13 | path := filepath.Dir(os.Args[0]) 14 | var err error 15 | database, err = sql.Open("sqlite3", path+"/storages.db") 16 | if err == nil { 17 | _, err = os.Stat(path + "/storages.db") 18 | if err != nil { 19 | _, _ = database.Exec(`CREATE TABLE IF NOT EXISTS storages ("key" TEXT NOT NULL PRIMARY KEY, "value" TEXT);`) 20 | } 21 | } 22 | } 23 | 24 | // Get 从本地存储中取出键值为key的数据并返回。 25 | func Get(key string) string { 26 | var value string 27 | query := `SELECT value FROM storages WHERE key = ?` 28 | _ = database.QueryRow(query, key).Scan(&value) 29 | return value 30 | } 31 | 32 | // Put 把值value保存到本地存储中。 33 | func Put(key, value string) { 34 | query := `INSERT OR REPLACE INTO storages (key, value) VALUES (?, ?)` 35 | _, _ = database.Exec(query, key, value) 36 | } 37 | 38 | // Remove 移除键值为key的数据。 39 | func Remove(key string) { 40 | query := `DELETE FROM storages WHERE key = ?` 41 | _, _ = database.Exec(query, key) 42 | } 43 | 44 | // Contains 返回该本地存储是否包含键值为key的数据。 45 | func Contains(key string) bool { 46 | var exists bool 47 | query := `SELECT EXISTS(SELECT 1 FROM storages WHERE key = ?)` 48 | _ = database.QueryRow(query, key).Scan(&exists) 49 | return exists 50 | } 51 | 52 | // Clear 移除该本地存储的所有数据。 53 | func Clear() { 54 | query := `DELETE FROM storages` 55 | _, _ = database.Exec(query) 56 | } 57 | -------------------------------------------------------------------------------- /system/system.go: -------------------------------------------------------------------------------- 1 | package system 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "runtime" 8 | "strconv" 9 | "strings" 10 | 11 | "github.com/Dasongzi1366/AutoGo/files" 12 | "github.com/Dasongzi1366/AutoGo/utils" 13 | ) 14 | 15 | func GetPid(processName string) int { 16 | if processName == "" { 17 | return os.Getpid() 18 | } 19 | output := utils.Shell("ps") 20 | lines := strings.Split(output, "\n") 21 | for _, line := range lines { 22 | if strings.HasSuffix(line, processName) { 23 | fields := strings.Fields(line) 24 | pid, err := strconv.Atoi(fields[1]) 25 | if err == nil { 26 | return pid 27 | } 28 | return -1 29 | } 30 | } 31 | return -1 32 | } 33 | 34 | func GetMemoryUsage(pid int) int { 35 | if pid == 0 { 36 | pid = os.Getpid() 37 | } 38 | 39 | cmd := fmt.Sprintf("cat /proc/%d/status | grep -e VmRSS", pid) 40 | output := utils.Shell(cmd) 41 | lines := strings.Split(output, "\n") 42 | 43 | for _, line := range lines { 44 | if strings.Contains(line, "VmRSS") { 45 | fields := strings.Fields(line) 46 | if len(fields) >= 2 { 47 | memory, err := strconv.Atoi(fields[1]) 48 | if err == nil { 49 | return memory 50 | } 51 | } 52 | } 53 | } 54 | 55 | return -1 56 | } 57 | 58 | func GetCpuUsage(pid int) float64 { 59 | if pid == 0 { 60 | pid = os.Getpid() 61 | } 62 | 63 | cmd := fmt.Sprintf("top -b -n 1 | grep '^ *%d '", pid) 64 | output := utils.Shell(cmd) 65 | lines := strings.Split(output, "\n") 66 | 67 | for _, line := range lines { 68 | fields := strings.Fields(line) 69 | if len(fields) > 8 { 70 | cpuUsage, err := strconv.ParseFloat(fields[8], 64) 71 | if err == nil { 72 | return cpuUsage 73 | } 74 | } 75 | } 76 | 77 | return 0.0 // 返回 0.0 表示查询失败 78 | } 79 | 80 | func RestartSelf() { 81 | os.Exit(123) 82 | } 83 | 84 | func SetBootStart(enable bool) { 85 | path := filepath.Dir(os.Args[0]) 86 | if os.Getenv("APPPID") != "" { 87 | utils.Shell("rm -rf /data/local/tmp/start") 88 | utils.Shell("rm -rf /data/adb/service.d/AutoGo.sh") 89 | if enable { 90 | utils.Shell("touch " + path + "/BootStart") 91 | } else { 92 | utils.Shell("rm -rf " + path + "/BootStart") 93 | } 94 | return 95 | } 96 | 97 | utils.Shell("rm -rf " + path + "/BootStart") 98 | 99 | if !enable { 100 | utils.Shell("rm -rf /data/local/tmp/start") 101 | utils.Shell("rm -rf /data/adb/service.d/AutoGo.sh") 102 | return 103 | } 104 | 105 | if !strings.Contains(utils.Shell("whoami"), "root") { 106 | fmt.Println("开机自启设置失败,无root权限") 107 | return 108 | } 109 | 110 | cmd := `#!/system/bin/sh 111 | while [ "$(getprop sys.boot_completed)" != "1" ]; do 112 | sleep 1 113 | done 114 | sleep 5 115 | ` + os.Args[0] + " -bootstart=1" 116 | 117 | if dirExists("/data/adb/modules") { 118 | utils.Shell("mkdir /data/adb/service.d") 119 | _ = os.WriteFile("/data/adb/service.d/AutoGo.sh", []byte(cmd), 0644) 120 | utils.Shell("chmod 755 /data/adb/service.d/AutoGo.sh") 121 | return 122 | } 123 | 124 | _ = os.WriteFile("/data/local/tmp/start", []byte(cmd), 0644) 125 | utils.Shell("chmod 755 /data/local/tmp/start") 126 | 127 | utils.Shell("mount -o rw,remount /system") 128 | str := utils.Shell("mount -o rw,remount /") 129 | if str != "" && (runtime.GOARCH == "amd64" || runtime.GOARCH == "386") { 130 | fmt.Println("系统分区挂载失败,请在模拟器性能设置中开启System.vmdk可写入") 131 | return 132 | } 133 | 134 | cil := ` 135 | 136 | (typepermissive adbd) 137 | (typepermissive shell) 138 | 139 | ;; +exec typeattributeset file_type, exec_type, mlstrustedobject 140 | ;; + typeattributeset domain, mlstrustedobject, mlstrustedsubject, netdomain, coredomain 141 | 142 | ` 143 | if files.Exists("/system/etc/selinux/plat_sepolicy.cil") && !strings.Contains(files.Read("/system/etc/selinux/plat_sepolicy.cil"), cil) { 144 | utils.Shell("rm -rf /system/etc/selinux/*.sha256") 145 | files.Append("/system/etc/selinux/plat_sepolicy.cil", cil) 146 | } 147 | 148 | rc := ` 149 | 150 | on property:sys.boot_completed=1 151 | start autogo 152 | 153 | service autogo /system/bin/sh /data/local/tmp/start 154 | seclabel u:r:su:s0 155 | oneshot 156 | 157 | ` 158 | 159 | if !strings.Contains(files.Read("/system/etc/init/logd.rc"), rc) { 160 | files.Append("/system/etc/init/logd.rc", rc) 161 | } 162 | 163 | utils.Shell("mount -o ro,remount /system") 164 | utils.Shell("mount -o ro,remount /") 165 | } 166 | 167 | func dirExists(path string) bool { 168 | info, err := os.Stat(path) 169 | if err != nil { 170 | // 如果出错,可能是不存在,也可能是权限问题 171 | return false 172 | } 173 | return info.IsDir() 174 | } 175 | -------------------------------------------------------------------------------- /utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | /* 4 | #include 5 | #include 6 | #include 7 | #include 8 | #cgo arm64 LDFLAGS: -L../libs/arm64-v8a -lAutoGo 9 | #cgo amd64 LDFLAGS: -L../libs/x86_64 -lAutoGo 10 | #cgo 386 LDFLAGS: -L../libs/x86 -lAutoGo 11 | 12 | void logI(const char* label,const char* message) { 13 | __android_log_print(ANDROID_LOG_INFO, label, "%s", message); 14 | } 15 | 16 | void logE(const char* label, const char* message) { 17 | __android_log_print(ANDROID_LOG_ERROR, label, "%s", message); 18 | } 19 | 20 | char* shell(const char* cmd); 21 | */ 22 | import "C" 23 | import ( 24 | "math/rand" 25 | "strconv" 26 | "strings" 27 | "time" 28 | "unsafe" 29 | ) 30 | 31 | func LogI(label, message string) { 32 | cLabel := C.CString(label) 33 | defer C.free(unsafe.Pointer(cLabel)) 34 | cMessage := C.CString(message) 35 | defer C.free(unsafe.Pointer(cMessage)) 36 | C.logI(cLabel, cMessage) 37 | } 38 | 39 | func LogE(label, message string) { 40 | cLabel := C.CString(label) 41 | defer C.free(unsafe.Pointer(cLabel)) 42 | cMessage := C.CString(message) 43 | defer C.free(unsafe.Pointer(cMessage)) 44 | C.logE(cLabel, cMessage) 45 | } 46 | 47 | func Shell(cmd string) string { 48 | cCmd := C.CString(cmd) 49 | defer C.free(unsafe.Pointer(cCmd)) 50 | 51 | cResult := C.shell(cCmd) 52 | defer C.free(unsafe.Pointer(cResult)) 53 | 54 | return C.GoString(cResult) 55 | } 56 | 57 | func Random(min, max int) int { 58 | if min > max { 59 | min, max = max, min // 如果 min 大于 max,则交换两者 60 | } 61 | rand.Seed(time.Now().UnixNano()) 62 | return rand.Intn(max-min+1) + min 63 | } 64 | 65 | func Sleep(i int) { 66 | time.Sleep(time.Duration(i) * time.Millisecond) 67 | } 68 | 69 | func I2s(i int) string { 70 | return strconv.Itoa(i) 71 | } 72 | 73 | func S2i(s string) int { 74 | i, _ := strconv.Atoi(strings.TrimSpace(s)) 75 | return i 76 | } 77 | 78 | // F2s 将浮点数转换为字符串。 79 | func F2s(f float64) string { 80 | return strconv.FormatFloat(f, 'f', -1, 64) 81 | } 82 | 83 | // S2f 将字符串转换为浮点数。如果转换失败返回0.0。 84 | func S2f(s string) float64 { 85 | f, _ := strconv.ParseFloat(strings.TrimSpace(s), 64) 86 | return f 87 | } 88 | 89 | // B2s 将布尔值转换为字符串 ("true" 或 "false")。 90 | func B2s(b bool) string { 91 | if b { 92 | return "true" 93 | } 94 | return "false" 95 | } 96 | 97 | // S2b 将字符串转换为布尔值。如果无法转换则返回 false。 98 | func S2b(s string) bool { 99 | b, _ := strconv.ParseBool(strings.TrimSpace(s)) 100 | return b 101 | } 102 | -------------------------------------------------------------------------------- /yolov5/yolov5.go: -------------------------------------------------------------------------------- 1 | package yolov5 2 | 3 | /* 4 | #include "yolov5.h" 5 | #include 6 | #cgo arm64 LDFLAGS: -L../../resources/libs/arm64-v8a -lyolov5 7 | #cgo amd64 LDFLAGS: -L../../resources/libs/x86_64 -lyolov5 8 | #cgo 386 LDFLAGS: -L../../resources/libs/x86 -lyolov5 9 | */ 10 | import "C" 11 | import ( 12 | "encoding/json" 13 | "fmt" 14 | "github.com/Dasongzi1366/AutoGo/images" 15 | "strings" 16 | "unsafe" 17 | ) 18 | 19 | type YoloV5 struct { 20 | pointer *C.YoloV5 21 | } 22 | 23 | type DetectResult struct { 24 | X int `json:"X"` 25 | Y int `json:"Y"` 26 | Width int `json:"宽"` 27 | Height int `json:"高"` 28 | Label string `json:"标签"` 29 | Score float64 `json:"精度"` 30 | CenterX int `json:"-"` //中心坐标X 31 | CenterY int `json:"-"` //中心坐标Y 32 | } 33 | 34 | func New(cpuThreadNum int, paramPath, binPath, labels string) *YoloV5 { 35 | pointer := C.newYoloV5() 36 | if pointer == nil { 37 | return nil 38 | } 39 | 40 | cParamPath := C.CString(paramPath) 41 | defer C.free(unsafe.Pointer(cParamPath)) 42 | 43 | cBinPath := C.CString(binPath) 44 | defer C.free(unsafe.Pointer(cBinPath)) 45 | 46 | cLabels := C.CString(labels) 47 | defer C.free(unsafe.Pointer(cLabels)) 48 | 49 | result := C.loadModelYoloV5(pointer, cParamPath, cBinPath, cLabels, C.int(cpuThreadNum)) 50 | goResult := C.GoString(result) 51 | C.free(unsafe.Pointer(result)) 52 | if goResult != "OK" { 53 | fmt.Println("yolov5:" + goResult) 54 | return nil 55 | } 56 | return &YoloV5{pointer: pointer} 57 | } 58 | 59 | func (y *YoloV5) Detect(x1, y1, x2, y2 int) []DetectResult { 60 | img := images.CaptureScreen(x1, y1, x2, y2) 61 | if img == nil { 62 | return nil 63 | } 64 | 65 | result := C.detectYoloV5( 66 | y.pointer, 67 | (*C.uchar)(unsafe.Pointer(&img.Pix[0])), 68 | C.int(img.Rect.Dx()), 69 | C.int(img.Rect.Dy()), 70 | C.float(0.5), 71 | C.float(0.45), 72 | C.int(640), 73 | ) 74 | goResult := C.GoString(result) 75 | C.free(unsafe.Pointer(result)) 76 | fmt.Println(goResult) 77 | var results []DetectResult 78 | err := json.Unmarshal([]byte(goResult), &results) 79 | if err != nil { 80 | return nil 81 | } 82 | 83 | var validResults []DetectResult 84 | for _, result := range results { 85 | if strings.TrimSpace(result.Label) == "" { 86 | continue 87 | } 88 | result.X += x1 89 | result.Y += y1 90 | result.CenterX = result.X + result.Width/2 91 | result.CenterY = result.Y + result.Height/2 92 | validResults = append(validResults, result) 93 | } 94 | return validResults 95 | } 96 | 97 | func (y *YoloV5) Close() { 98 | C.closeYoloV5(y.pointer) 99 | } 100 | -------------------------------------------------------------------------------- /yolov5/yolov5.h: -------------------------------------------------------------------------------- 1 | #ifndef YOLOV5_H 2 | #define YOLOV5_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | typedef struct YoloV5 YoloV5; 9 | 10 | YoloV5* newYoloV5(); 11 | 12 | const char *loadModelYoloV5(YoloV5 *obj, const char *param_path, const char *bin_path, const char* labels, int num_threads); 13 | 14 | char *detectYoloV5(YoloV5 *obj, const unsigned char *bitmapData, int width, int height, float nms, float prob, int size); 15 | 16 | void closeYoloV5(YoloV5 *obj); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif // YOLOV5_H 23 | --------------------------------------------------------------------------------