[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

Protection Fault on GetQuadrangleSubPix (Beta5)

Solution


Use WarpAffine with complete settings for rotation and translation
rotated: image by: angleDegrees
	" Private - Returns an IPL image rotated by angle degrees, and return the resulting image.
	The argument image will be released (if required). "

	| destination factor matrix r1 r2 lpValues angle center delta |
	angleDegrees \\ 360 = 0 ifTrue: [ ^image ].
	angleDegrees \\ 360 = 180 ifTrue: [
		destination := image clone.
	] ifFalse: [
		destination := IPLImage
			extent: image extent transpose
			depth: image depth channels: image channels.
	]. 
	angle := (angleDegrees negated \\ 360) degreesToRadians.
	center := image extent // 2.
	delta := destination extent - image extent // 2.
	matrix := CvMat rows: 2 cols: 3 type: (OpenCVConstants at: 'Cv32f').
	r1 := Array
		with: angle cos with: angle sin
		with: center x - (center x * angle cos) - (center y * angle sin) + delta x.
	r2 := Array
		with: (r1 at: 2) negated with: r1 first
		with: center y + (center x * angle sin) - (center y * angle cos) + delta y.
	lpValues := (OpenCVSinglePrecisionFloatArray withAll: r1,r2)
		asByteArray copyToExternalMemory.
	matrix setTo: lpValues.
	image warpAffine: destination with: matrix.
	image release.
	lpValues free.
	matrix release.
	Float clearExceptionFlags. "clear float exceptions"
	^destination

Error description

TypeError (Bug?)
versionBeta5
DetailProtection Fault when rotating image of extent=2048x3072
CommentsThe error was not present on Beta4.
Does not reproduce for other extents (640x960), nor for rotated image (3072x2048).
Ref.Please send comments to aleReimondo@smalltalking.net

Code snippet

image := HighGUI file loadImage: 'img_6790.jpg'.
angle := -90.

    angle = 180 ifTrue: [
        destination := image clone.
        factor := 1.
    ] ifFalse: [
        destination := IPLImage
            extent: image extent transpose
            depth: image depth channels: image channels.
        factor := 0.5 * angle sign.
    ].
    matrix := CvMat rows: 2 cols: 3 type: (OpenCVConstants at: 'Cv32f').
    r1 := Array
        with: (factor * Float pi) cos
        with: (factor * Float pi) sin
        with: image width * 0.5.
    r2 := Array
        with: (r1 at: 2) negated
        with: r1 first
        with: image height * 0.5.
    lpValues := (OpenCVSinglePrecisionFloatArray withAll: r1,r2)asByteArray copyToExternalMemory.
    matrix setTo: lpValues step: 16r7FFFFFFF.
    image getQuadrangleSubPix: destination with: matrix.
    image release.
    lpValues free.
    matrix release.
destination asDIB inspect.

Image to be used to test the failure

Uploaded Image: IMG 6790.JPG