This is the 21st day of my participation in Gwen Challenge
Image rollovers
Image rollovers
Image flipping operation is to flip the image two-dimensional array along the horizontal axis, vertical axis or two axes.
Image transpose
Image transpose operation is to perform image matrix transpose operation.
The image to repeat
An image copy operation populates an output image with a duplicate copy of the input image.
Image symmetry
Copy the lower or upper half of the square matrix to the other half.
API
Image rollovers
public static void flip(Mat src, Mat dst, int flipCode)
Copy the code
- Parameter one: SRC, enter the image.
- Parameter two: DST, the output image, the size and type of the original image.
- Parameter 3: flipCode, flip flag bit. 0 means flip along the X axis, and positive numbers like 1 mean flip along the Y axis. A negative number such as -1 is flipped along the X-axis and Y-axis.
Image transpose
public static void transpose(Mat src, Mat dst)
Copy the code
- Parameter one: SRC, enter the image.
- Parameter two: DST, the output image, the size and type of the original image.
The image to repeat
public static void repeat(Mat src, int ny, int nx, Mat dst)
Copy the code
- Parameter one: SRC, enter the image.
- Parameter 2: ny, how many times to copy in Y direction.
- Parameter 3: nx, the number of copies in the X-axis direction.
- Parameter 4: DST, output image, the type is the same as the original image.
Image symmetry
public static void completeSymm(Mat m, boolean lowerToUpper)
Copy the code
-
Parameter 1: SRC, input image square matrix, is also the output image.
-
Argument two: lowerToUpper, if true, copies the lower part to the upper part. Otherwise, copy the top half to the bottom half.
operation
/** * 图 文 转 转 * author: yidong * 2020/12/20 */
class FlipActivity : AppCompatActivity() {
private val mList = mutableListOf<ImageTextObject>()
private val mAdapter by lazy { ImageTextAdapter(this, mList) }
private val mBinding: ActivityFlipBinding by lazy {
ActivityFlipBinding.inflate(layoutInflater)
}
private val rgb: Mat by lazy {
val bgr = getBgrFromResId(R.drawable.lena)
bgr.toRgb()
}
override fun onCreate(savedInstanceState: Bundle?). {
super.onCreate(savedInstanceState)
setContentView(mBinding.root)
mBinding.container.adapter = mAdapter
wrapCoroutine({ showLoading() }, { doFlip() }, { hideLoading() })
}
override fun onDestroy(a) {
rgb.release()
super.onDestroy()
}
private fun doFlip(a) {
val resultX = Mat()
val resultY = Mat()
val resultXY = Mat()
val resultTranspose = Mat()
val resultRepeat = Mat()
Core.flip(rgb, resultX, 0)
Core.flip(rgb, resultY, 1)
Core.flip(rgb, resultXY, -1)
Core.transpose(rgb, resultTranspose)
Core.repeat(rgb, 2.2, resultRepeat)
val resultSymmetryLowerToUpper = rgb.clone()
Core.completeSymm(resultSymmetryLowerToUpper, true)
val resultSymmetryUpperToLower = rgb.clone()
Core.completeSymm(resultSymmetryUpperToLower, false)
mList.add(ImageTextObject(rgb, "Original"))
mList.add(ImageTextObject(resultX, "X-flip"))
mList.add(ImageTextObject(resultY, "Y-flip"))
mList.add(ImageTextObject(resultXY, "XY reversal"))
mList.add(ImageTextObject(resultTranspose, "Transposed"))
mList.add(ImageTextObject(resultRepeat, "repeat"))
mList.add(ImageTextObject(resultSymmetryLowerToUpper, "Symmetry from bottom to top."))
mList.add(ImageTextObject(resultSymmetryUpperToLower, "Symmetry from top to bottom."))}private fun showLoading(a) {
mBinding.isLoading = true
}
private fun hideLoading(a) {
mBinding.isLoading = false
mAdapter.notifyDataSetChanged()
}
}
Copy the code
The effect
The source code
Github.com/onlyloveyd/…