Method for automatically adjusting photo direction and mobile terminal
Technical Field
The invention relates to the field of mobile terminals, in particular to a method for automatically adjusting the direction of a photo and a mobile terminal.
Background
With the rapid development of integrated circuit technology, mobile terminals have been provided with powerful processing capabilities, and mobile terminals are changing from simple communication tools to an integrated information processing platform. Modern mobile terminals already have a very powerful processing power, memory, a solidified storage medium and a computer-like operating system.
An existing operating system of a mobile terminal can provide a powerful multimedia photographing function, wherein a transverse screen and a vertical screen are switched to each other, a user can use two photographing modes of the transverse screen and the vertical screen under the default condition, however, due to the fact that photographing angles are different, the situation that the viewing angle is not in accordance with the normal habit of the user can occur when the user displays the photos in the transverse screen photographing mode again in the mobile terminal or the computer, the user is required to manually rotate the photos when browsing, and when the user browses numerous photos with different angles, the user experience is greatly reduced due to complex operation.
To solve this problem, in the prior art, a method for automatically adjusting the direction of a photo is as follows: as shown in fig. 1, when a photo is taken from multiple angles, a driving Layer of the direction sensing device obtains triaxial data of the gravitational acceleration of the current mobile terminal in real time, and a Hardware Abstraction Layer (HAL) of the direction sensing device obtains inclination angle data according to the triaxial data, and sends the inclination angle data to an application program module of the camera module for storage through a call interface; meanwhile, the driving layer of the camera module acquires image data returned by the camera and sends the image data to the HAL of the camera module, the HAL of the camera module sends the image data to the image coding module for coding, and the image data is stored in the memory after the coding of the image coding module is finished; the application program module of the camera module records the inclination angle data into the file header information of the photo, and when the photo is browsed again on the mobile terminal, the application program of the photo library rotates the photo by a certain angle according to the recorded inclination angle data. The method is to store the image data in the memory after the encoding of the image encoding module is completed, and if the picture is browsed on the mobile terminal, the picture is adjusted according to the inclination angle data, that is, the image data is stored first and then adjusted, so the method has the defect that once the picture is separated from the mobile terminal, for example, the picture is placed on a computer to be displayed, the picture is restored to the angle when the picture is taken, and the direction of the picture still needs to be manually adjusted by a user, as shown in fig. 2. When a user browses a plurality of photos at different angles continuously, the direction of the photos is adjusted once according to the current inclination data angle when the user opens one photo, and browsing efficiency is reduced.
Disclosure of Invention
In view of the above, the present invention provides a method for automatically adjusting a direction of a photo and a mobile terminal, where the direction of the photo taken from multiple angles is automatically adjusted on the mobile terminal.
In order to achieve the purpose, the technical scheme of the invention is realized as follows:
the invention discloses a mobile terminal for automatically adjusting the direction of a photo, which comprises: the direction sensing device, the camera module and the image coding module; wherein,
the direction sensing device is used for sending the inclination angle data of the mobile terminal to the camera module;
the camera module is used for obtaining direction data of the mobile terminal according to the inclination angle data; after the image data are obtained, the image data and the direction data are sent to an image coding module;
and the image coding module is used for processing the image data according to the direction data and storing the processed image data into the memory.
In the above mobile terminal, the direction sensing apparatus includes: a driver layer, a Hardware Abstraction Layer (HAL), a calling interface; wherein,
the driving layer is used for acquiring triaxial data of the gravity acceleration of the current mobile terminal in real time and sending the triaxial data to the HAL;
the HAL is used for calling a driving program, calculating inclination angle data of the mobile terminal according to the triaxial data by using an inverse trigonometric function formula, and sending the inclination angle data to a calling interface;
and the calling interface is used for receiving the inclination angle data sent by the HAL and sending the inclination angle data to the camera module.
In the above mobile terminal, the camera module includes: an application module, a service layer, a Hardware Abstraction Layer (HAL); wherein,
the application program module is used for obtaining the direction data of the mobile terminal according to the inclination angle data sent by the direction sensing device and sending the direction data to the service layer;
the service layer is used for receiving the direction data sent by the application program module and sending the direction data to the HAL;
and the HAL is used for acquiring the image data and sending the image data and the direction data to the image coding module.
The invention also discloses a method for automatically adjusting the direction of the photo, which comprises the following steps:
the direction sensing device sends the inclination angle data of the mobile terminal to the camera module;
the camera module obtains direction data of the mobile terminal according to the inclination angle data, and sends the image data and the direction data to the image coding module after obtaining the image data;
and the image coding module processes the image data according to the direction data and stores the processed image data in a memory.
In the above method, the sending, by the direction sensing device, the tilt angle data of the mobile terminal to the camera module specifically includes:
a driving layer of a direction sensing device in the mobile terminal acquires triaxial data of the current gravitational acceleration of the mobile terminal in real time; and the HAL of the direction sensing device calls a driving program, calculates the inclination angle data of the mobile terminal by using an inverse trigonometric function formula according to the triaxial data, and sends the inclination angle data to an application program module of the camera module through a calling interface of the direction sensing device.
In the above method, the obtaining, by the camera module, the direction data of the mobile terminal according to the tilt angle data specifically includes:
four directions are predefined in an application module of the camera module, the application module of the camera module receives the tilt angle data, determines the direction in which the tilt angle data is located, and sends the direction data of the direction to the HAL of the camera module through a service layer of the camera module.
In the method, the four directions are respectively a 0-degree direction, a 90-degree direction, a 180-degree direction and a 270-degree direction, wherein the 0-degree, 90-degree, 180-degree and 270-degree directions are included angles between an X-axis and a horizontal plane and along a clockwise direction, and each angle direction represents a direction of an angle within a range of plus or minus 45 degrees.
In the above method, the processing the image data by the image coding module according to the direction data, and storing the processed image data in the memory specifically includes:
the encoding principle is predefined in the image encoding module, the image encoding module determines the encoding order of the Minimum Coding Unit (MCU) of the image data according to the direction data sent by the HAL of the camera module by using the encoding principle, encodes and compresses the image data, and directly stores the image data in the memory.
In the above method, the determining, by the image coding module, the coding order of the MCU of the image data according to the direction data sent by the HAL of the camera module by using the coding principle specifically includes:
if the direction is 0 degree, the width and the height of the image data do not need to be interchanged, and the MCU at the upper left corner of the image data starts to encode; if the direction is 90 degrees, the width and the height of the image data are interchanged, and the MCU at the upper right corner with the image data at 0 degree as the reference starts to encode; if the direction is 180 degrees, the width and the height of the image data are not interchanged, and the MCU at the lower right corner with the image data at 0 degree as the reference starts to encode; if the direction is 270 degrees, the width and the height of the image data are interchanged, and the MCU at the lower left corner with the image data at 0 degree as the reference starts to encode.
The invention provides a method and a mobile terminal for automatically adjusting the direction of a photo, which can automatically adjust the direction of the photo according to the angle during photographing by using a direction sensing device and an image coding technology, and then store the adjusted photo, so that the scheme in the invention is to store image data according to the viewing angle in accordance with the normal habit of a user, and when the photos taken at different angles are displayed again on the mobile terminal or a computer, the user does not need to manually adjust the direction of the photo one by one, thereby improving the browsing efficiency of the photo, greatly saving time and energy, and improving the user experience;
the method and the mobile terminal provided by the invention can be applied to various operating systems, wherein the Android operating system is an operating system with a public source code, so that when the scheme is applied to the Android operating system, a manufacturer of the mobile terminal does not reconfigure and modify the operating system in the mobile terminal through an enterprise with operating system modification permission, but modifies related configurations in the method automatically according to user requirements and the like, the application flexibility of the mobile terminal is improved, and the research, development and production cost of the manufacturer of the mobile terminal is reduced.
Drawings
FIG. 1 is a schematic diagram of a prior art structure for automatically adjusting the direction of a photo;
fig. 2 is an exemplary diagram of a photograph taken by a mobile terminal in a prior art when displayed in a computer;
FIG. 3 is a schematic structural diagram of a mobile terminal for automatically adjusting the photo direction according to the present invention;
FIG. 4 is a flowchart illustrating a method for automatically adjusting the direction of a photo according to the present invention;
FIG. 5 is a three-dimensional coordinate system based on a plane of a mobile terminal according to the present invention;
fig. 6 is an exemplary view of a photograph taken by a mobile terminal in the present invention when displayed in a computer.
Detailed Description
The invention provides a method and a Mobile terminal for automatically adjusting the direction of a photo, which can be applied to various operating systems, such as a Windows Mobile operating system, a Symbian operating system, an Android operating system and the like, and the basic idea is as follows: the direction sensing device sends the inclination angle data of the mobile terminal to the camera module; the camera module obtains direction data of the mobile terminal according to the inclination angle data; after the image data are obtained, the image data and the direction data are sent to an image coding module; and the image coding module processes the image data according to the direction data and stores the processed image data in a memory.
The invention is further described in detail below with reference to the drawings and the specific embodiments.
The invention provides a mobile terminal for automatically adjusting the direction of a photo, and fig. 3 is a schematic structural diagram of the mobile terminal for automatically adjusting the direction, as shown in fig. 3, the device includes: a direction sensing device 31, a camera module 32, an image encoding module 33; wherein,
a direction sensing means 31 for transmitting tilt angle data of the mobile terminal to the camera module 32;
a camera module 32 for obtaining direction data of the mobile terminal according to the tilt angle data; after acquiring the image data, sending the image data and the direction data to the image coding module 33;
the image coding module 33 is configured to process the image data according to the direction data, and store the processed image data in the memory;
the direction sensing device 31 further includes: a driver layer 311, a Hardware Abstraction Layer (HAL)312, a call interface 313; wherein,
the driving layer 311 is configured to obtain digitized triaxial data of the gravitational acceleration of the current mobile terminal in real time, and send the triaxial data to the HAL 312;
HAL312, configured to call a driver, calculate, according to the three-axis data and using an inverse trigonometric function formula, to obtain tilt angle data of the mobile terminal, and send the tilt angle data to the call interface 313;
call-up interface 313 for receiving the tilt angle data sent by HAL312 and sending the data to camera module 32;
the camera module 32 further includes: application module 321, service layer 322, Hardware Abstraction Layer (HAL) 323; wherein,
the application module 321 is configured to obtain direction data of the mobile terminal according to the inclination angle data sent by the calling interface 313, and send the direction data to the service layer 322;
the application module 321 obtains the direction data of the mobile terminal according to the tilt angle data sent by the call interface 313, and sending the direction data to the service layer 322 specifically includes: defining four directions in an application program module 321 in advance, wherein the application program module 321 receives the inclination angle data, determines the direction of the inclination angle data, and sends the direction data to the HAL323 through a service layer 322; the four directions are respectively a 0-degree direction, a 90-degree direction, a 180-degree direction and a 270-degree direction, the 0-degree direction, the 90-degree direction, the 180-degree direction and the 270-degree direction are included angles between an X axis and a horizontal plane and along a clockwise direction, and each angle direction represents a direction of an angle within a range of plus or minus 45 degrees of the value;
a service layer 322, configured to receive the direction data sent by the application module 321, and send the data to the HAL 323;
a HAL323 for acquiring image data and sending the image data and the direction data to the image encoding module 33;
the image encoding module 33 processes the image data according to the direction data, and stores the processed image data in the memory specifically as follows: the image coding module determines the coding sequence of a Minimum Coding Unit (MCU) of the image data according to the direction data sent by the HAL323, codes and compresses the image data, and directly stores the image data in a memory;
the image encoding module 33 determines the encoding order of the MCU of the image data according to the direction data sent by the HAL323, specifically: if the direction is 0 degree, the width and the height of the image data do not need to be interchanged, and the MCU at the upper left corner of the image data starts to encode; if the direction is 90 degrees, the width and the height of the image data are interchanged, and the MCU at the upper right corner with the image data at 0 degree as the reference starts to encode; if the direction is 180 degrees, the width and the height of the image data are not interchanged, and the MCU at the lower right corner with the image data at 0 degree as the reference starts to encode; if the direction is 270 degrees, the width and the height of the image data are interchanged, and the MCU at the lower left corner with the image data at 0 degree as the reference starts to encode.
The invention provides a method for realizing automatic adjustment of photo direction, fig. 4 is a flow diagram of the method for realizing automatic adjustment of photo direction, as shown in fig. 4, the method comprises the following steps:
step 401, the direction sensing device obtains inclination angle data according to the three-axis data of the mobile terminal and sends the inclination angle data to an application program module of the camera module;
specifically, as shown in fig. 5, the Z axis is always perpendicular to the plane of the mobile terminal, the X axis and the Y axis are always located on the plane of the mobile terminal and are perpendicular to each other, so as to form a three-dimensional coordinate system based on the plane of the mobile terminal, when the mobile terminal rotates, the gravitational acceleration applied to the mobile terminal may generate components on the X axis, the Y axis and the Z axis, and when the mobile terminal takes a picture from multiple angles, the driving layer of the direction sensing device in the mobile terminal acquires the digitized three-axis data of the gravitational acceleration of the current mobile terminal on the X axis, the Y axis and the Z axis of the mobile terminal in real time; the direction sensing device can be a gravity sensor, an acceleration sensor, a magnetic field sensor and the like;
the HAL of the direction sensing device calls a driving program, the inclination angle data of the mobile terminal is obtained through calculation by using an inverse trigonometric function formula according to the triaxial data of the mobile terminal, which is obtained by a driving layer of the direction sensing device, and the inclination angle data is sent to an application program module of the camera module through a calling interface of the direction sensing device;
step 402, the application program module of the camera module obtains the direction data of the mobile terminal according to the inclination angle data, and sends the direction data to the HAL of the camera module through the service layer of the camera module;
specifically, the application module in the camera module is configured, that is, four directions are predefined in the application module of the camera module, which are respectively a 0-degree direction, a 90-degree direction, a 180-degree direction, and a 270-degree direction, where 0 degree, 90 degrees, 180 degrees, and 270 degrees are included angles between an X-axis and a horizontal plane and along a clockwise direction, each angle direction represents a direction of an angle within a range of plus or minus 45 degrees of a numerical value of the angle, the application module of the camera module receives the tilt angle data, determines a direction in which the tilt angle data is located, and sends the direction data of the direction to the HAL of the camera module through a service layer of the camera module;
step 403, the HAL of the camera module acquires image data and sends the image data and the direction data to the image coding module;
specifically, in practical application, a driver in a driver layer of the camera module may drive a chip of a camera of the mobile terminal to record an image, store the captured image in a kernel space, and the HAL of the camera module obtains image data by copying the image data of the image from the kernel space to a user space, and sends the image data and the received direction data to the image encoding module;
step 404, the image coding module processes the image data according to the direction data and stores the processed image data in a memory;
specifically, the image coding module divides the received image data into a plurality of MCUs with 8 × 8 pixels, a coding principle is predefined in the image coding module, and the image coding module determines a coding order of the MCUs of the image data according to the direction data sent by the HAL of the camera module by using the coding principle, where the coding principle is as follows: if the direction is 0 degree, the width and the height of the image data do not need to be interchanged, and the MCU at the upper left corner of the image data starts to encode; if the direction is 90 degrees, the width and the height of the image data are interchanged, and the MCU at the upper right corner with the image data at 0 degree as the reference starts to encode; if the direction is 180 degrees, the width and the height of the image data do not need to be interchanged, and the MCU at the lower right corner with the image data at 0 degree as the reference starts to encode; if the direction is 270 degrees, exchanging the width and the height of the image data, and starting coding by using the MCU at the lower left corner with the image data at 0 degree as a reference; the encoding process comprises the steps of performing discrete cosine transform on image data, namely converting the time domain of the image data into the frequency domain, concentrating light intensity on a plurality of controllable coefficients, performing quantization arrangement on the controllable coefficients, rearranging the image data after quantization arrangement, and placing the lowest light frequency at the forefront; in addition, it is also necessary to encode the dc coefficients in the image data using differential pulse code modulation, encode the ac coefficients in the image data using run length coding, and finally further compress the image data using entropy coding, where the compression process may include lossy compression and lossless compression; the image coding module determines the order, codes and compresses the image data, and then directly stores the image data into a main memory or an external memory, wherein the external memory can be a T-flash card and the like; after storing the image data, the image coding module may send a completion instruction that the image has been processed and saved to the application module of the camera module via the HAL of the camera module and the service layer of the camera module.
As shown in fig. 6, since the stored image data is the image data adjusted according to the direction data, when the image is displayed again in the mobile terminal or the computer, since the image data has been stored according to the viewing angle in conformity with the normal habit of the user, the user is not required to manually rotate the image direction any more; this function may not be enabled according to the user's needs, and when it is not needed, it may be masked by selecting no in the menu of this function of the application module of the camera module.
The above description is only exemplary of the present invention and should not be taken as limiting the scope of the present invention, and any modifications, equivalents, improvements, etc. that are within the spirit and principle of the present invention should be included in the present invention.